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);
}
}
{
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);
}
}
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q689q
顺便问一句有什么方法禁止调整Column的宽度.
还有我觉得要实现鼠标选一整行也没必要如此麻烦嘛
dgridAccount.CurrentCell =
new DataGridCell(dgridAccount.CurrentCell.RowNumber,dgridAccount.CurrentCell.ColumnNumber);
dgridAccount.Select(dgridAccount.CurrentRowIndex);
我就是这样做的,但是CurrentCell却总是只有文本部分被选中,空白部分却是灰色,也无法改变它的颜色,我现在要做的就是只要把空白部分也设为高亮的颜色就可以了
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); //行
// dataGrid1.Select(hti.Column); //列
} 写在mouse_up事件下面
private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){
dataGrid1.Select(dataGrid1.CurrentRowIndex);
}
用键盘的话,再Currentcellchanged事件里yong
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
dataGrid1.Select(dataGrid1.CurrentRowIndex);
}可以选定整行,但效果不是很好
有一种方法:重画DataGird就不会出现了
{
dataGrid1.Select(dataGrid1.CurrentRowIndex);
}