Datagrid sorting and connection to Access

ses41

Member
Joined
Apr 17, 2002
Messages
13
I have a few questions I was hoping to get some help with.

First question:

I have a datagrid in with I have set the Sorting property to true. When I click the top of any column, the datagrid becomes sorted by that column. However, the index stays with the physical row and does not sort with the data.

Am I understanding this correctly? Is there any way to have the index stay with the record when I click the sort at the top of the column.

Second question:

When I look at a table within Access, the tables default view is sorted by the Primary ID column. But when I bring it into a VB.NET datagrid, the rows represented by the first two Primary ID numbers show up at the bottom of the datagrid. Does anyone know how or why this happens.

Third question:

I have purchased 3 books on ADO.NET, but what I am really looking for is a book that gives a list of all commands available and gives an example of their use. Can anyone recommend such a book?

Thanks
 
1) The index number of a control is supposed to work this way, the index is the location of each element, just like an array. Imagine if you were to loop from lowerBound(0) to upperBound (10) but the data was re-sorted, that would be a mess.

2) You should be including an Order By in your sql statement if you want a specific sort order.

3) You would need a Reference guide then, I dont know of any. MSDN/F1 usually has info like this.
 
Robby,

Thanks for your reply. I will use sort by, although I was real curious why VB.NET would automatically sort this way when the data was not entered that way. Probably more curious than I need to be. Also thanks for the advise on #3.

Concerning #1, I am not sure of your response. The problem is that my data becomes as mess. When I first see the datagrid the index numbers are 0 to count-1 and my "ID" numbers are in numerical order. When I then sort on a column, the index numbers stay at 0 to count-1, but the "ID" numbers are all mixed- up according to what is sorted.

Therefore the index numbers and "ID" numbers do not stay together. I could see where this could be useful if you were trying to use, lets say, the first 10 names on a list in alphabetical order. But since using "position" is the only way I know to point to a record, I would like it to stay with the record no matter how it is sorted. I just thought there might a property or something that would help me do this.

What I am doing now is looping through the whole dataset one position at a time to find the "ID" I am looking for. When I find it, then I know I am current on that record, and the index is of no help to me. I am aniticipating when the number of records gets real large, that this will slow down the program.

Thanks again
 
The index is there so you can iterate from 0 to count, you cannot use the index in any collection as a Key.

The reason that the grid is not sorted as it is in Access is that Access knows which column is the PK column, you must explicitly tell the grid which column holds the PK (Primary Key).
 
Robby,


The problem is that the index is the only thing I can use to make a certain row "current".

I dont have VB.net on this computer, so some of the coding below might not make sense.

I have used something like this.

Dim r as dsSource.dsRow

r = dsSource.dsTable.FINDBYID(integer)

So I can sort of point to r, but r is not current. So how can I tell what the index of r is, so that I can point to it.

I guess I could rewrite a lot of my program to use r.lastname = instead of .current("lastname")=


Can I do something like this?

Dim idx as index

idx=dsSource.dsTable.FINDBYID(integer)

me.bindingContext(dsSource, "dsTable").position=idx
 
Back
Top