473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Discrepancy in DataGridView column order & databound DataTable

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
Jul 25 '06 #1
3 2457
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:uv**************@TK2MSFTNGP02.phx.gbl...
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

Jul 26 '06 #2

Ken Tucker [MVP] wrote:
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:uv**************@TK2MSFTNGP02.phx.gbl...
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.

Jul 26 '06 #3
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11********************@m79g2000cwm.googlegrou ps.com...
>
Ken Tucker [MVP] wrote:
>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.
>----------------------------
"Mike" <nonewrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
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.
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
Jul 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob | last post by:
During a form's development I noticed that when I changed bound dataset defintions with the dataset designer (for instance adding a column to one), when I come back and look at the form the...
3
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
0
by: cris.b | last post by:
Hi, I have a question about ordering column in a DataGridView. I have a databound DataGridView with the AutoGenerateColumn property set to true. I want to change column's order. At runtime I...
2
by: Martin | last post by:
Hi all, This is the situation... DatagridView Control with datasource set to datatable. I want the user to be able to delete x number of rows by selecting a row with mouse then clicking a...
1
by: twq | last post by:
hello I have a datagridview in which one column is a datagridCombobox Column which is data bound, in the second column the user is allowed to enter what ever he wants, and i want the user to...
4
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
how do you insert a new row to a databound datagridview? It won't allow this action.
1
by: sklett | last post by:
I've got a strange situation here. I have a databound DataGridView that also has un-bound columns. When the view loads, I want to update the values of the unbound columns. If I attempt to modify...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.