How to detect cell click in DataGrid?
How to detect what specific cell was cli开发者_JAVA百科cked in DataGrid?
I'm pretty sure you're looking for the selectedindexchanged event
Did you try to handle CellClik or CellContentClick events?
Suppose I haven't found this answer as well, (To determine a cell click). And suppose I wanted to use it to be able to check/uncheck a checkbox, upon first click.
Then I guess the designer of this library would not approve of doing, it the following way, (I can (de)select my checkbox this way, but it seems unwise/dangerous as your changing the selected item property of the grid.)
So what we need is someone telling us how we can detect a cell's click otherwise some of us
may want to use the selectionchanged event, the bad thing about this is that you lose info on
which row of the grid pass pressed.
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (dataGridInstance.SelectedItem != null)
{
//do what you need to do with the data. (for example start with:)
Microsoft.Windows.Controls.DataGridCellInfo datagridCellInfo = dataGridInstance.CurrentCell;
//when you are done, set selectiTem to null, so even upon a next click on the same
//cell this method will be called again
dataGridTeam.SelectedItem = null;
}
}
精彩评论