We help IT Professionals succeed at work.

Silverlight DataGrid with checkboxes

knopr
knopr used Ask the Experts™
on
My Silverlight 3 application contains a DataGrid with checkboxes. These checkboxes require two clicks to check or uncheck them. One to activate/select the row and the second the check or uncheck. How can I reduce this to one click? Is it for instance possible to activate the row on the mouseover event?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In your Datagrid create a MouseLeftButtonUp event.


private void DataGrid1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
    //Specify the column location of the checkbox 
    int cbCol = 0;
 
    if (DataGrid1.CurrentColumn == DataGrid1.Columns[cbCol]){
      
      CheckBox cb= (DataGrid1.CurrentColumn.GetCellContent(DataGrid1.SelectedItem) as CheckBox);
       //Check or uncheck the checkbox         
       cb.IsChecked = !cb.IsChecked;
      }
 
        }

Open in new window

Author

Commented:
Thanks Craig, exactly what I needed.