views:

70

answers:

1

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.

A: 

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

ctacke
Too bad. Funny thing is something like `dataGrid1.Select(1);` `dataGrid1.Select(2);` (inside a OnButtonClick) will select the second and third rows of the grid (with out any custom drawing), so the code to allow multi draw seems to be in there somewhere...
Vaccano