日期:2014-05-20  浏览次数:20885 次

dataGrid1控件问题??
我在dataGrid1控件里显示一个表的信息,各位   怎样实现点击其中一个字段,整行数据都被选中。

------解决方案--------------------
首先建立一个组件类 DataGridNoActiveCellColumn
using System;
using System.Windows.Forms;
using System.Drawing;

namespace Windowsdatagrid
{
internal class DataGridNoActiveCellColumn :System.Windows.Forms.DataGridTextBoxColumn
{

protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
int SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRow);
}
}
}

------解决方案--------------------
DataGridTableStyle ts1 = new DataGridTableStyle();
DataGridNoActiveCellColumn aColumnTextColumn=new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName= "custID ";
aColumnTextColumn.HeaderText= "序号 ";
aColumnTextColumn.NullText= " ";
aColumnTextColumn.Format= "F ";
ts1.GridColumnStyles.Add(aColumnTextColumn);
dataGrid1.TableStyles.Add(ts1);
当你点击 "序号 "这行的单元格时候,就会自动选中这一行
------解决方案--------------------
5.11 How can I select the entire row when the user clicks on a cell in the row?

Call the DataGrid.Select method from within its mouseup event.

[C#]

private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)

{

System.Drawing.Point pt = new Point(e.X, e.Y);

DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);

if(hti.Type == DataGrid.HitTestType.Cell)

{

dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);

dataGrid1.Select(hti.Row);

}

}



[VB/NET]

Private Sub dataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dataGrid1.MouseUp

Dim pt = New Point(e.X, e.Y)

Dim hti As DataGrid.HitTestInfo = dataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then

dataGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column)

dataGrid1.Select(hti.Row)

End If

End Sub


------解决方案--------------------
congrui() 与 Knight94(愚翁) 的为正解!

DataGrid相关问题,可参考如下说明:

http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx#44