I had searched a lot, but all answers were vague. I have tried on my own and did it.
for (int j = 0; j < dataGrid1.Columns.Count; j++)
{
for (int i = 0; i < dataGrid1.Items.Count - 1; i++)
{
string s=(dataGrid1.Items[i] as DataRowView).Row.ItemArray[j].ToString();
}
}
i,j are the co-ordinates. So you can play around it.
for (int j = 0; j < dataGrid1.Columns.Count; j++)
{
for (int i = 0; i < dataGrid1.Items.Count - 1; i++)
{
string s=(dataGrid1.Items[i] as DataRowView).Row.ItemArray[j].ToString();
}
}
i,j are the co-ordinates. So you can play around it.
thank you very much
ReplyDeleteI need to put this code inside: SuchAnEventDataBindingCompleted(.. )
ReplyDeleteI'll find it soon. :)
Thanks.
A working DataBindingCompletedEvent:
ReplyDelete...
dataGrid1.DataContext = dataSet.Tables[0].DefaultView ;
dataGrid1.AutoGenerateColumns = true;
...
private void dataGrid1_AutoGeneratedColumns(object sender, EventArgs e)
{
string s = (dataGrid1.Items[3] as DataRowView).Row.ItemArray[0].ToString();
MessageBox.Show(s);
}
That is not a cell! try to change the background color...
ReplyDeleteI was searching for this for a long time.
ReplyDeleteThank you very much.
Does not work!
ReplyDeleteError : Object reference not set .... on line
string s=(dataGrid1.Items[i] as DataRowView).Row.ItemArray[j].ToString();
Thank you for this quiet simple solution. There are others, but they are so 'from behind through the chest in the eye' ;-)
ReplyDeleteThank you !
Simple and brilliant, thank you.
ReplyDeleteEvery other solution was way more complicated than it needed to be.