user626528
user626528

Reputation: 14409

How to detect cell click in DataGrid?

How to detect what specific cell was clicked in DataGrid?

Upvotes: 1

Views: 3549

Answers (3)

HCP
HCP

Reputation: 1042

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;
    }
}

Upvotes: 0

ingo
ingo

Reputation: 5569

I'm pretty sure you're looking for the selectedindexchanged event

Upvotes: 1

Adi
Adi

Reputation: 5223

Did you try to handle CellClik or CellContentClick events?

Upvotes: 0

Related Questions