System.Windows.Forms.DataGrid (CF) 上的多项选择

发布于 2024-09-02 15:25:50 字数 689 浏览 1 评论 0原文

有没有办法对标准数据网格进行多重选择? (我正在使用紧凑框架。)


这就是我最终所做的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渔村楼浪 2024-09-09 15:25:50

不是天生的,不是。您必须自己处理 SelectedRows 并自定义绘制它< /a>.

Not inherently, no. You'd have to handle the SelectedRows yourself and custom draw it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文