Using the DataGrid Control

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Why is there no reference out there (at least I can't find them) that
show the very basics of using a datagrid. All I want to do is set up
a grid with 2 columns, not bound to any data. Basically, how do I add
columns with headers, name them, and remove the record indicators?
The 'gotdotnet' references only show how to do this with bound data,
so no help to me.
 
The DataGrid is a data bound control. You generally interface your data
through the use of a DataTable and the DataGrid's DataSource property. Most
of the material that you find in relation to the DataGrid in the full
framework should apply to the DataGrid in the CF.
 
Fair enough...but does the grid have to be bound, or can I just use a
datasource, create and populate the grid, and then use it unbound?
 
You can't "populate" the grid as it does not have internal data storage.

It would fetch data (for visible rows only) from bound data source and show
it on a screen, it won't copy the data.

This is a huge performance benefit if you have many rows.



If you don't want to use data binding for some reason, you can use other
controls.

For example, ListView control is similar to the data grid and it does not
support data binding.

Thus, you can (or rather have to) populate it manually.



Best regards,



Ilya



This posting is provided "AS IS" with no warranties, and confers no rights.
 
You cannot add and remove rows through a simple "Add" or "Remove" method of
the DataGrid. To add and remove items you will need to directly work with
the data source (DataTable, DataView, etc.). However, to modify a particular
field value within the DataGrid you can do something similar to the
following.
Me.DataGrid1.Item(rowNum, colNum) = newVal
 
Back
Top