How to select and get the value of a cell in WPF?

0

[I'm pretty new to WPF]

I would like to know how I can obtain the value of a cell or several in WPf, I am currently working on a project and I need to be able to select a cell or several cells and obtain their value. Once this is achieved, I would like to give a button and receive that value from the cells to be able to deal with it within the button event. What method do I have to create in the cs and with what property do I assign that data to that datagrid so that when I press the button I can obtain the value of the cells?

Thanks in advance. Greetings.

    
asked by Francisco Rabasco Díaz-Chirón 05.03.2018 в 14:27
source

1 answer

2

You do not need any event in your datagrid.

The datagrid has a SelectedItems or SelectedCells property, which returns the items that are selected in your grid (or cells).

With selectionMode and SelectionUnit, in your grid, you define the selection mode that you want to apply when the user stands over a cell.

Here depends on the selection mode you use for your grid, the way you go through the selection.

If SelectionUnit is in FullRow, you will have to go through it like this:

foreach (var i in grilla.SelectedItems)

If SelectionUnit is in any of the other two modes, you will have to go through it like this:

foreach (var i in grilla.SelectedCells)

All this, you can do in the event click on the button itself.

    
answered by 05.03.2018 / 18:34
source