Datagrid - setting column sort programmatically

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

I have bound a datagrid to a table in a dataset.

Clicking a column to sort the presented grid rows works great. I have
managed the indexing issues fine.

I need to be able to preserve this sort order when necessary to refresh
my dataset programmatically (dataset is manually created), or between
program runs. This means I need to be able to both get and set the
current datagrid sort setting. I have browsed the objects in the
debugger, but can not find it.
 
Lee said:
I have bound a datagrid to a table in a dataset.

Clicking a column to sort the presented grid rows works great. I have
managed the indexing issues fine.

I need to be able to preserve this sort order when necessary to refresh
my dataset programmatically (dataset is manually created), or between
program runs. This means I need to be able to both get and set the
current datagrid sort setting. I have browsed the objects in the
debugger, but can not find it.

I think I see this. Since my grid holds a hierarchical display, via a
datarelationship declared on tables in my manually created dataset, I
must be aware of the table being displayed at the time. I can retrieve
both the table name, and sort setting (and set them) via something like
this...

' Save settings prior to each load of the dataset
' Be sure DataSource not null, as in first time load
Dim cm As CurrencyManager = CType( _
dgWO.BindingContext(dgWO.DataSource, dgWO.DataMember), _
CurrencyManager)
Dim dv As DataView = CType(cm.List, DataView)
TableName = dv.Table.TableName
Sort = dv.Sort
SaveSetting("MyApplukashun", "Sort", TableName, Sort)

dgWo.DataSource = myDS
dgWo.DataMember = "MainTableName"

' After the DataSource property has been set
Dim cm As CurrencyManager = CType( _
dgWO.BindingContext(dgWO.DataSource, dgWO.DataMember), _
CurrencyManager)
Dim dv As DataView = CType(cm.List, DataView)
TableName = dv.Table.TableName
Sort = GetSetting("MyApplukashun", "Sort", TableName, "")
dv.Sort = Sort
 
Back
Top