System.Windows.Forms.DataGrid (CF) 上的多项选择
有没有办法对标准数据网格进行多重选择? (我正在使用紧凑框架。)
这就是我最终所做的:
readonly List<int> _selectedRows = new List<int>();
private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
{
int c = dataGrid1.CurrentRowIndex;
if (_selectedRows.Contains(c))
{
dataGrid1.UnSelect(c);
_selectedRows.Remove(c);
// Take focus off the current row if I can
if (_selectedRows.Count > 0)
dataGrid1.CurrentRowIndex = _selectedRows[0];
}
else
{
_selectedRows.Add(c);
}
foreach (int rowIndex in _selectedRows)
{
dataGrid1.Select(rowIndex);
}
}
有点像穷人的多重选择,但它有效。
Is there a way to do multi-selction on with the standard datagrid? (I am using the compact framework.)
This is what I ended up doing:
readonly List<int> _selectedRows = new List<int>();
private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
{
int c = dataGrid1.CurrentRowIndex;
if (_selectedRows.Contains(c))
{
dataGrid1.UnSelect(c);
_selectedRows.Remove(c);
// Take focus off the current row if I can
if (_selectedRows.Count > 0)
dataGrid1.CurrentRowIndex = _selectedRows[0];
}
else
{
_selectedRows.Add(c);
}
foreach (int rowIndex in _selectedRows)
{
dataGrid1.Select(rowIndex);
}
}
Kind of a poor man's mulit select, but it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是天生的,不是。您必须自己处理 SelectedRows 并自定义绘制它< /a>.
Not inherently, no. You'd have to handle the SelectedRows yourself and custom draw it.