回复 4楼Alice的帖子
- C1.Silverlight.DataGrid.DataGridRow row;
- //List to keep track of current selection
- List<C1.Silverlight.DataGrid.DataGridRow> selectedRows;
- void Presenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- selectedRows = this.c1DataGrid1.Selection.SelectedRows.ToList();
- }
- void Presenter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- row = ((C1.Silverlight.DataGrid.DataGridRowPresenter)sender).Row;
- /* If CTRL key has been pressed the entire code is not needed anyways.
- * With SelectionMode set to MultiRow the grid will take care of
- * addition/removal of rows from selection*/
- if ((!C1.Silverlight.KeyboardUtil.Ctrl))
- {
- Dispatcher.BeginInvoke(() =>
- {
- if (selectedRows.Contains(row))
- {
- selectedRows.Remove(row);
- }
- else
- {
- selectedRows.Add(row);
- }
- //Clear selection before we impose a new one
- c1DataGrid1.Selection.Clear();
- foreach (var r in selectedRows)
- {
- this.c1DataGrid1.Selection.Add(r, r);
- }
- });
- }
- }
复制代码
不是指高亮颜色的设置,是指在不用Ctrl键时鼠标点击多个行时,被点击的多个行这时要处于行选中的高亮效果,之前您提过要通过代码才能实现这效果,上面关键代码是c1DataGrid1.Selection,只要把选中的多个行加入到这个Selection集合里,那么多个选中的行的高亮效果是自然会显示出来
上面的效果是要通过c1DataGrid1控件设置,在MVVM模式里基本上不直接访问控件来处理特定事情,我这里想问的是,在ViewModel里有没有不直接通过使用控件c1DataGrid1.Selection这方式的其它方案来达到上面所说的效果 |