C
clogg02
Hi,
I have bound a DataView to a DataGridView using
this.dataGridView1.DataSource = new
DataView(this.dataTable1);
I allow for sorting of the datagridview using clicks on the headers.
Later on I need to determine the content of any selected cell or row
in that datagridview once a button has been pressed.
My event handler:
private void button1_Click(object sender, EventArgs e)
{
DataView dv1 = ((DataView)this.dataGridView1.DataSource);
if (dv1 != null)
{
DataTable dt = dv1.Table;
DataRow dr =
dt.Rows[this.dataGridView1.SelectedCells[0].RowIndex];
// gives the same :
// DataRow dr =
dt.Rows[this.dataGridView1.SelectedCells[0].OwningRow.Index];
unfortunately looking at this.dataGridView1.SelectedCells[0].RowIndex
gives the index that would have been valid in the unsorted
datagridview. Is there a way of getting to the 'sorted' Index ? I have
tried calling this.dataGridView1.Refresh() but all to no avail. Thanks.
I have bound a DataView to a DataGridView using
this.dataGridView1.DataSource = new
DataView(this.dataTable1);
I allow for sorting of the datagridview using clicks on the headers.
Later on I need to determine the content of any selected cell or row
in that datagridview once a button has been pressed.
My event handler:
private void button1_Click(object sender, EventArgs e)
{
DataView dv1 = ((DataView)this.dataGridView1.DataSource);
if (dv1 != null)
{
DataTable dt = dv1.Table;
DataRow dr =
dt.Rows[this.dataGridView1.SelectedCells[0].RowIndex];
// gives the same :
// DataRow dr =
dt.Rows[this.dataGridView1.SelectedCells[0].OwningRow.Index];
unfortunately looking at this.dataGridView1.SelectedCells[0].RowIndex
gives the index that would have been valid in the unsorted
datagridview. Is there a way of getting to the 'sorted' Index ? I have
tried calling this.dataGridView1.Refresh() but all to no avail. Thanks.