0

I have a text box search bar in my WPF application that displays records in a datagrid if they match the textbox content. The DataGrid has 2 cells- The first is a string and the second is an Int. I would like to retrieve the int values from the second cell in every row by clicking a separate search button. I unfortunately cannot seem to figure out how to accomplish this.

      string ID = (DataGrid.SelectedCells[1].Column.GetCellContent(0) as TextBlock).Text;
dsj24
  • 39
  • 4

1 Answers1

0

About Retrieve The Specific Cell

The way to get the cell by row and colunm info:

https://stackoverflow.com/a/11615729/12949439

You can use the GetCell(int row, int colunm) method which created by @LPL in loops to get all cells in the DataGrid.

After you get all the cells, you can find the specific cell in them, and select it.


About Select The Specific Cell

The DataGrid has a SelectionUnit property, and you can set it into DataGridSelectionUnit.SingleCell then you can just select cell instead of select whole row.

And you can also use the SelectedCells property to get or set the selected cell(s).

And if you want the user can only select one cell, you can set SelectionMode property into DataGridSelectionMode.Single, so the user can not select multi-cells.

And for more infomation, you read the MSDN document about DataGrid, about DataGrid.SelectionUnit, about DataGrid.SelectedCells, and about DataGrid.SelectionMode.