datagrid control

  • Thread starter Thread starter Phill Shaw
  • Start date Start date
P

Phill Shaw

Hello All -

Can someone point me to an article or some sample code that will help me
out? I've got a datagrid on a form and I want to do some wacky things like
size the columns when the data populates and tap on a column header and sort
the data <---MSDN says you can't do this because you can't bind a datagrid
to a dataset, but my datagrid is bound to a dataset...

Thanks in advance -
ps
 
Binding a DataGrid to a DataSet (Or more precisely a DataTable within a
DataSet) is possible - In fact this is essentially the primary purpose of
the control.
However the control is very limited in terms of formatting and other
features such as editing which are available on the desktop control. No
event is exposed for clicking on column headers (although you can catch
CurrentCellChanged and determine the column which is selected). If you want
to provide resorting of your data you would probably want to bind the
DataGrid to a DataView as opposed to the DataTable itself - then you can
change this DataView to provide a sorted view of the underlying table:-

DataView dv = new DataView(dataTable);

dv.Sort("FieldName ASC");

dv.Sort("AnotherField DESC");


Peter
 
Wow... I thought that was going to be the hard part...

Back to the limited functionality; I don't see anything that's going to
allow me to dynamically size the columns on the fly.

Thanks again for the clarification on the use of DS vs. DV !!

ps -
 
Back
Top