Simple grid/table display question.

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

I've got a simple form that collects data from a user and I want to display
that data in a sortable grid or table. The nature of this data is rather
temporary, so there's no need to persist it to a database. Searching through
the Framework documentation, everything I've seen reggarding a grids and
tables seems to require a connection to a database. My guess is I'm just
missing something. What classes can I use to display sortable data in a grid
or table that don't require a DB connection?

Thanks in advance,
Will.
 
Will,

The DataGrid can connect to anything that implements IList. Each row
will be whatever is served up by the IList interface. The grid uses
reflection to get the columns. However, if the type implements ITypedList
(like the DataView does), then it will query the members of that interface
to get the columns.

Also, the DataSet class (and DataTable, etc, etc classes) are not
connected to a database. You can create them and populate them as you wish,
without a database connection, and then pass this to the grid for binding.

Hope this helps.
 
You can create a DataTable to use as the data source for
your grid. Filling that table from a db is one option,
but it is not required.

using System.Data;

DataTable myTable = new DataTable("Info");
myTable.Columns.Add("ID");
myTable.Columns.Add("Name");
myTable.Columns.Add("Address");

DataRow dr = myTable.NewRow();
dr["ID"] = "4A";
dr["Name"] = "Johnny Frank";
dr["Address"] = "456 Second St";
myTable.Rows.Add(dr);

dr = myTable.NewRow();
dr["ID"] = "13E";
dr["Name"] = "Dweezil";
dr["Address"] = "123 Main St";
myTable.Rows.Add(dr);

this.dataGrid1.DataSource = myTable;

Charlie
 
Will,
I personaly prefer to keep things inside a Dataset. I provides alot of
functionality for knowing which rows of data have been modified, deleted and
so forth. You can easily create one and fill a DataTable inside it with
DataRows as the user enters data. From this table, you can create a
DataView which can sort and filter rows for you. You can then bind the
DataView to your Datagrid.

hope this helps

Marco
 
Back
Top