【DataGrid简单问题】:如何鼠标单击dataGrid中的数据,显示为1行选中,代码好用立即给分 在MouseDown事件中截获点中消息然后用DataGrid中的select、unselect、currentRowIndex等属性或方法搞定。自己试试看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在你点击datagrid时候,会有个selectedindexchanged事件发生。在这个里面就可以捕捉你要的行号 this.dataGrid.Select(int row);this.dataGrid.UnSelect(int row); 补充: this.dataGrid1.CurrentCell.RowNumber;this.dataGrid1.CurrentRowIndex; 在DataGrid的事件private void DataGrid1_ItemDataBound()中给DataGrid加一个属性:if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){ for (int i=0;i<e.Item.Cells.Count;i++) { e.Item.Cells[i].Attributes.Add("onclick", " alert " + e.Item.ItemIndex +"); }}就可以看到你点击任何一行中任何一列的行号 datagrid1.currentcell.rownumberdatagrid1.currentcell.rowindex都可以得到当前选种的行。在处理事件里边写上就行了啊! 还是我来吧 protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) { System.Drawing.Point pt = new Point(e.X,e.Y); DataGrid.HitTestInfo hti = this.HitTest(pt); if (hti.Type == DataGrid.HitTestType.Cell) { this.CurrentCell = new DataGridCell(hti.Row,hti.Column); this.Select(hti.Row); } }上面是我继续DataGrid里写的重载,你要是写在外面,请做相应的修改 datagrid1.select( datagrid1.currentrowindex);好像这样就OK了。 private void dataGrid_Main_Click(object sender, System.EventArgs e) { this.dataGrid_Main .Select (this.dataGrid_Main .CurrentRowIndex ); } DataGrid1.SelectedIndex=i;//I为你选择的行 //鼠标单击DataGrid,当前单元格被改变,用CurrentCellChanged事件。private void DataGrid1_CurrentCellChanged(object sender, System.EventArgs e){ //高亮显示当前行 this.DataGrid1.Select(this.DataGrid1.CurrentRowIndex); //当前行号 MessageBox.Show(this.DataGrid1.CurrentCell.RowNumber.ToString());} 你在CurrentCellChanged、clicked事件中添加datagrid1.select( datagrid1.currentrowindex);试试看。 private void dbGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){ System.Windows.Forms.DataGrid.HitTestInfo myHitTest; myHitTest = dbGrid.HitTest(e.X,e.Y); if (myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell) { dbGrid.Select(dbGrid.CurrentCell.RowNumber); }} 各位大虾,不要老是对WINDOW 操作好不好,有没有对WEB操作的呀!不过我看了,没几个能用的。我想对WEB上的DATAGRID 操作,同样的问题(高亮显示选中的行) private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { Point pt = new Point(e.X,e.Y); System.Windows.Forms.DataGrid.HitTestInfo hit = this.dataGrid1.HitTest(pt); if (hit.Type == DataGrid.HitTestType.Cell) { int row = this.dataGrid1.CurrentCell.RowNumber; this.dataGrid1.Select(row); } if (hit.Type == DataGrid.HitTestType.RowHeader) { int row = this.dataGrid1.CurrentCell.RowNumber; this.dataGrid1.Select(row); } } 谁能用公司C#编程规范修改下此文档,并且注释下! 如何解决asp.net中文件的上传和下载超过4M的问题,有着独到的见解,等待高手的解决! 样式问题? 关于C# winform程序读写ACCESS数据库的问题 硬盘分区的注册表信息在什么地方 GUID的问题 求C#代码把datatable中的数据填充到treeview 【附详细示例代码】关于对象实现IDisposable接口,使用Dispose()方法释放资源的疑问 C#如何将string类型转换为16进制数 三角形第三边长。 datagrid问题 怎样得到当前应用程序的路径?
this.dataGrid.UnSelect(int row);
this.dataGrid1.CurrentCell.RowNumber;this.dataGrid1.CurrentRowIndex;
给DataGrid加一个属性:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
for (int i=0;i<e.Item.Cells.Count;i++)
{
e.Item.Cells[i].Attributes.Add("onclick", " alert " + e.Item.ItemIndex +");
}
}
就可以看到你点击任何一行中任何一列的行号
datagrid1.currentcell.rowindex
都可以得到当前选种的行。在处理事件里边写上就行了啊!
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X,e.Y);
DataGrid.HitTestInfo hti = this.HitTest(pt);
if (hti.Type == DataGrid.HitTestType.Cell)
{
this.CurrentCell = new DataGridCell(hti.Row,hti.Column);
this.Select(hti.Row);
}
}上面是我继续DataGrid里写的重载,你要是写在外面,请做相应的修改
{
this.dataGrid_Main .Select (this.dataGrid_Main .CurrentRowIndex );
}
private void DataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
//高亮显示当前行
this.DataGrid1.Select(this.DataGrid1.CurrentRowIndex);
//当前行号
MessageBox.Show(this.DataGrid1.CurrentCell.RowNumber.ToString());
}
datagrid1.select( datagrid1.currentrowindex);试试看。
{
System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
myHitTest = dbGrid.HitTest(e.X,e.Y);
if (myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell)
{
dbGrid.Select(dbGrid.CurrentCell.RowNumber);
}
}
不过我看了,没几个能用的。我想对WEB上的DATAGRID 操作,同样的问题(高亮显示选中的行)
{
Point pt = new Point(e.X,e.Y);
System.Windows.Forms.DataGrid.HitTestInfo hit = this.dataGrid1.HitTest(pt);
if (hit.Type == DataGrid.HitTestType.Cell)
{
int row = this.dataGrid1.CurrentCell.RowNumber;
this.dataGrid1.Select(row); }
if (hit.Type == DataGrid.HitTestType.RowHeader)
{
int row = this.dataGrid1.CurrentCell.RowNumber;
this.dataGrid1.Select(row);
}
}