开发者

Multi selection on System.Windows.Forms.DataGrid (CF)

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 curr开发者_运维技巧ent 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜