Loading Grids

billy_bob169

Freshman
Joined
Jan 30, 2003
Messages
32
Location
Minnesota
I built a simple project in VB6, and I loaded a Flex Grid control using a loop and some simple formulas based on the users input. I have been trying to build the same project in VB.Net, but have yet to find a way to load a grid. I don't want the grid to be tied to a database, I just want to load it the way I did before. Is there any way to do this? I really don't want to be using COM objects, and I am trying to get away from them!! Someone please help if you can...:(
 
You can bind a datagrid to a disconnected dataset I think, but I haven't actually done this myself. Searching Google with those keywords will probably help you.
 
You must bind your grid to a DataSet or something that supports IBindingList and maybe another interface or two.

You definitely do not need a database to use a DataSet. You can load one a number of ways - completely manually if you wanted to. If you have valid XML you can load a DataSet using the ReadXml() method. If you use XmlReadMode.InferSchema it will build a schema for you...

-Nerseus
 
I should have mentioned that to create an "unbound" DataSet you simply create it like any other object. You can add tables and columns pretty easily, too.

For example:
C#:
DataSet ds = new DataSet("MyDataSet");
DataTable dt = ds.Tables.Add("MyTable");

dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("LastName", typeof(string));
dt.Columns.Add("DOB", typeof(DateTime));

DataRow row;

// Add all values in one shot
dt.Rows.Add(new object[] {1, "Dan", "Jones", new DateTime(1971, 11, 28)});

// Add all values in an array
ArrayList a = new ArrayList();
a.Add(2);
a.Add("Carl");
a.Add("Jones");
a.Add(new DateTime(2001, 11, 1));
dt.Rows.Add(a.ToArray());

// OR Add explicitly (my favorite)
row = dt.NewRow();
row["ID"] = 3;
row["FirstName"] = "Bob";
row["LastName"] = "Jones";
row["DOB"] = new DateTime(2000, 1, 1);
dt.Rows.Add(row);

// Show the results
Debug.WriteLine(ds.GetXml());

-Nerseus
 
Thanks a ton for your help. The example code you included helps clear up a lot of questions I had. This forum is really a great help for people like myself, struggling to learn .Net. I'll let you know what I figure out.
 
Back
Top