Connecting Tech Pros Worldwide Forums | Help | Site Map

Discrepancy in DataGridView column order & databound DataTable

Mike
Guest
 
Posts: n/a
#1: Jul 25 '06
Dear group,

I'm currrently investigating a bug within a piece of our software whereby if
a DataGridView (bound directly to a DataTable) is ordered by column headers
(containing lookup combo boxes where the value is the foreign key of another
table), although the DataGridView is ok, the DataTable becomes out of sync.

In other words, I have a Grid of customers, and if a customer name column
header is clicked - the data moves in the DataGridView, but previous data is
still held for the original row positions in the DataTable.

This throws off row calculations quite considerably, and is a particularly
fustrating bug to debug.

Any ideas are most welcome, and thanks in advance for any advice.

Regards,

Mike



Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Jul 26 '06

re: Discrepancy in DataGridView column order & databound DataTable


Mike,

The datagridview is actually bound to the datatable's defaultview.
That will have the records in the right order.

Ken
----------------------------
"Mike" <nonewrote in message news:uvbGZuAsGHA.4004@TK2MSFTNGP02.phx.gbl...
Quote:
Dear group,
>
I'm currrently investigating a bug within a piece of our software whereby
if a DataGridView (bound directly to a DataTable) is ordered by column
headers (containing lookup combo boxes where the value is the foreign key
of another table), although the DataGridView is ok, the DataTable becomes
out of sync.
>
In other words, I have a Grid of customers, and if a customer name column
header is clicked - the data moves in the DataGridView, but previous data
is still held for the original row positions in the DataTable.
>
This throws off row calculations quite considerably, and is a particularly
fustrating bug to debug.
>
Any ideas are most welcome, and thanks in advance for any advice.
>
Regards,
>
Mike
>

Brian Tkatch
Guest
 
Posts: n/a
#3: Jul 26 '06

re: Discrepancy in DataGridView column order & databound DataTable



Ken Tucker [MVP] wrote:
Quote:
Mike,
>
The datagridview is actually bound to the datatable's defaultview.
That will have the records in the right order.
>
Ken
----------------------------
"Mike" <nonewrote in message news:uvbGZuAsGHA.4004@TK2MSFTNGP02.phx.gbl...
Quote:
Dear group,

I'm currrently investigating a bug within a piece of our software whereby
if a DataGridView (bound directly to a DataTable) is ordered by column
headers (containing lookup combo boxes where the value is the foreign key
of another table), although the DataGridView is ok, the DataTable becomes
out of sync.

In other words, I have a Grid of customers, and if a customer name column
header is clicked - the data moves in the DataGridView, but previous data
is still held for the original row positions in the DataTable.

This throws off row calculations quite considerably, and is a particularly
fustrating bug to debug.

Any ideas are most welcome, and thanks in advance for any advice.

Regards,

Mike
Wow, thanx, that clears something up for me too.

BTW, a way to simply test this would be to add a DataGridView, three
textboxes and a button. Then the following code:

Dim table As New DataTable

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim row As DataRow

table.Columns.Add()

row = table.NewRow
table.Rows.Add(row)
row(0) = "A"

row = table.NewRow
table.Rows.Add(row)
row(0) = "B"

DataGridView1.DataSource = table

End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = DataGridView1.Item(0, 0).Value.ToString
TextBox2.Text = table.Rows(0)(0).ToString
TextBox3.Text = table.DefaultView.Item(0)(0).ToString
End Sub

B.

Mike
Guest
 
Posts: n/a
#4: Jul 27 '06

re: Discrepancy in DataGridView column order & databound DataTable


"Brian Tkatch" <Maxwell_Smart@ThePentagon.comwrote in message
news:1153919429.516152.4290@m79g2000cwm.googlegrou ps.com...
Quote:
>
Ken Tucker [MVP] wrote:
Quote:
>Mike,
>>
> The datagridview is actually bound to the datatable's
>defaultview.
>That will have the records in the right order.
Ahhh, thank you. I think that will solve it.
Quote:
Quote:
>----------------------------
>"Mike" <nonewrote in message
>news:uvbGZuAsGHA.4004@TK2MSFTNGP02.phx.gbl...
Quote:
Dear group,
>
I'm currrently investigating a bug within a piece of our software
whereby
if a DataGridView (bound directly to a DataTable) is ordered by column
headers (containing lookup combo boxes where the value is the foreign
key
of another table), although the DataGridView is ok, the DataTable
becomes
out of sync.
>
In other words, I have a Grid of customers, and if a customer name
column
header is clicked - the data moves in the DataGridView, but previous
data
is still held for the original row positions in the DataTable.
>
This throws off row calculations quite considerably, and is a
particularly
fustrating bug to debug.
>
Any ideas are most welcome, and thanks in advance for any advice.
>
Regards,
>
Mike
>
>
Wow, thanx, that clears something up for me too.
Quote:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = DataGridView1.Item(0, 0).Value.ToString
TextBox2.Text = table.Rows(0)(0).ToString
TextBox3.Text = table.DefaultView.Item(0)(0).ToString
End Sub
^ Great example too. I'll have to do some recoding tonight. If any MSDN
article authors are reading this; this has got to be somewhere that a LOT of
people trip up on, but very little example documentation alludes to using
the .DefaultView.

Thanks!

Mike


Closed Thread