Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle click on a row and/or a cell of a datagrid in wpf

I have placed a Datagrid control on my WPF application and I'm trying to handle the mouse right click event on a row or a single cell of my Datagrid control. How can I achieve it? I've tried to capture the event with selectedItem executing the method but its not working "ciao"

Below is the xaml code:

<TabItem Header="Lista Dipendenti">
                <DataGrid x:Name="gridListaDipendenti" Margin="64,42,73,65"  SelectedItem="ciao"/>
</TabItem>

I wish I could execute some code when the user clicks a row or cell of the Datagrid and possibly get the value of the row (the ID).

like image 991
DarKAngeL Avatar asked Dec 20 '25 08:12

DarKAngeL


1 Answers

In visual basic, if you want to access the numberOfTheColum element of the numberOfTheRow row:

dataGridObject.Items(numberOfTheRow).Row(numberOfTheColum)

Besides that, there is a event called MouseRightButtonUp or something like that:

MouseRightButtonUp="methodName"

In that method name is where you can access the datagrid elements or even the cell pressed with datagridObject.CurrentCell

Hope it help

like image 156
Daniel Avatar answered Dec 21 '25 20:12

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!