我的winform中有一个databound gridview。我想知道如何获得当前选定行的索引,即多行。 我可以用一行来做到这一点。但有没有办法我可以有一个复选框或其中我可以索引多行。 下面的图片将帮助你更好地理解我的要求。winform多选网格行并获得选定行的行索引
1
A
回答
0
1
首先设置CellContentClick
事件您DataGridView
。
dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.onCellContentClick);
对于每个单元格单击它将调用以下方法。在这里您可以创建一个列表并使用点击的行索引填充它。
public void onCellContentClick(DataGridViewCellEventArgs cell)
{
// Check whether selected cell is check box column, here 0 indicates the check box column.
if (cell.ColumnIndex == 0)
{
bool isChecked = (Boolean) dataGridView[cell.ColumnIndex, cell.RowIndex].EditedFormattedValue;
if(isChecked)
{
// Below will give you the selected cell row index, for multiple rows you can populate those index in list or whatever you convenient with.
cell.RowIndex;
}
}
}
相关问题
- 1. TDBGrid选择行索引:如何获得
- 2. 获取GridView中选定行的索引
- 3. 如何获取WPF网格中选定单元格的行索引
- 4. 获取选定的Datagrid行索引或列索引
- 5. 如何获取JqWidgets网格中所有未选定行索引的列表
- 6. 选择具有多索引的行
- 7. Python,Pandas,选择多列索引的行
- 8. 如何获得剑道格行选择
- 9. 如何获得GridPanel的选定行ID
- 10. 如何获得行索引和按钮点击网格列
- 11. 获得具有给定行索引和列索引的datagrid单元格的值
- 12. 得到选定的行
- 13. 如何获取选定的索引时使用Ctrl + A键选择网格中的行
- 14. MVCContrib网格 - 选择行
- 15. 奇选择行为网格
- 16. Infragistics网格(行选择)
- 17. 如何根据jqgrid中的索引获取选定的行ID?
- 18. 在qml中获取选中复选框的行索引
- 19. 如何在JSF数据表中获取选定的行索引?
- 20. SQL:从查询中获取选定的行索引
- 21. 获取已过滤DataGrid中选定行的索引
- 22. 如何获得选定的行和列索引和计数在Word中JS
- 23. 如何删除数据网格上的多个选定的行
- 24. 有角度的网格标题行选择,选择所有行
- 25. 单元格行多选
- 26. 查找并选择多行
- 27. 如何从网格中删除多个选定的行
- 28. 如何获取kendo细节网格的选定行数据
- 29. 从动态CRM主网格中获取选定的行值
- 30. 如何获取网格视图选定行的数据库ID