0

I am looking for a way to read the value of allways one specific cell (Row:0, Column 2) in a DataGrid.

In WinForms it was very easy:

var1 = DataGridView1.Item(2, 0).Value

I am searching for hours now without finding anything usefull. It is important that I can choose values programatically, like in the way above, without preselections with mouse etc.

I hope someone knows an answer to that

Regards

gmetax
  • 3,853
  • 2
  • 31
  • 45
  • 1
    `c#` or `vb.net`? – Aethan Oct 18 '16 at 05:20
  • vb.net. Please note that this is a WPF project – Dr. Brackish Okun Oct 18 '16 at 06:36
  • if datagrid is data-bound, you should obtain values from from itemSource item. if not data-bound, please provide a complete reproducible example – ASh Oct 18 '16 at 06:57
  • I am opening an SQL-Connection an fill the data into a DataGrid. So far so good. In row 0 and column 2 is a value I need to assign to a variable. And this is the part which I am not able to solve to "just" assign this damn value in Row0 and Column2 to a variable. So all the data is there in the grid, but i am not able to take it out and use it further – Dr. Brackish Okun Oct 18 '16 at 07:17

2 Answers2

0
        int rowIndex = 2;
        int columnIndex = 0;
        var x = dataGridView1.Rows[rowIndex].Cells[columnIndex].Value;
0

i think this code can solve your problem.

string  Get_Cell_Value (int column, int row)
    {
        //Get Cell data to TextBlock
        TextBlock cell_data = dgGetInfo.Columns[column].GetCellContent(dgGetInfo.Items[row]) as TextBlock;
        return cell_data .Text.ToString();
    }

In the main program you can use it same:

cell_data_get = Get_Cell_Value(0,0)

It will get data from column[0], row[0] in your DataGrid I hope this code can help you.

Duy Nguyen
  • 31
  • 4