Determine WPF DataGrid cell value at runtime

Mar 12, 2010 at 9:29 PM
Edited Mar 12, 2010 at 9:30 PM

Hello,

I need to determine the value of a cell as the user clicks it.  I am using C# VS2010 RC.  For the life of me, I just can't seem to find out how.

Any help would be greatly appreciated

Mar 19, 2010 at 11:30 AM
kcwallace1996 wrote:

Hello,

I need to determine the value of a cell as the user clicks it.  I am using C# VS2010 RC.  For the life of me, I just can't seem to find out how.

Any help would be greatly appreciated

int index = this.dgrYourGrid.SelectedIndex;      //Datagrid Selected Row Number

MessageBox.Show("Row: " + index.ToString(), "Index");     //Show curent Row Number

string colname = dgrYourGrid.CurrentColumn.Header.ToString();  //Column Name

MessageBox.Show("Columnname " + colname, "Column");     //Show Column Name

object value = (this.dgrYourGrid.Items[index] as DataRowView)[colname];   //read Selectet Cell Content

MessageBox.Show("the value is " + value.ToString(), "Result");      //Show Result