DataGrid - Sorting Columns

  • Thread starter Thread starter Guest
  • Start date Start date
You can use one line of code to create a dataview from the datatable.

Dim dv as DataView = WhateverDataTable.DefaultView

Now, bind the grid to the view instead of the table. All of your
current
functionality will still be in tact.

You can call Sort on any field in the dataview and sort it which will
cause
the grid to sort.You could offer this via a context menu for instance,
if
for some reason you didn't want to allow sorting based on the grid
headers.

http://www.knowdotnet.com/articles/dataviewsort.html
 
Is there someother way such as sending a message to the DAtaGrid via WinProc
to sort a column? I don't see where the DataView works with DataSets.
 
Not tested, but how about something like this:

dim dv As New DataView
dv = ds.Tables(0).DefaultView 'where ds is the dataset in question
dv.Sort = "Order" 'where Order is the column name by which you want to sort
Me.DataGrid1.DataSource = dv
Me.DataGrid1.Refresh()
 
Talkin about dataview object. Recently I tried to edit some row like this
.... dr(indexcolumn) (indexrow) = "... " .. it was applied to the dataset,
But it didn't update to the datasource when i call
DataAdapter.update(Dataset,"TableName") { this with assumtion that
commandbuilder had been generated }. And also a mistake when i tried to
delete row using dataview object. But it didn't show any error message when
i put the -update method- in try ... catch ... endtry ....
Felling frustated with dataview object .. i used datatable object to edit
and delete row. ... Did u guys have this kind of problems before ?

Martin
 
Yes I did. I added beginedit and endedit and the problems were gone. I
thought begin/endedit was optional but it looks like it is obliged.
Frank
 
Back
Top