I'm storing a bunch of data in nested collections like this:
Dictionary<string, (holds tables)
.....Dictionary<string, (holds columns)
...............string type (names the type of data in column)
...............List<string> values (values for column)

Anyway I want to be able to display one of the individual tables (by column, with key of the second level dictionary as the header and values as the values) in a form, and have people select one column at a time and choose to perform various operations on it. I'm new to C# and .Net in general, but I looked around and found the DataGridView form element which seems to be the best choice, but I've had a lot of trouble getting it to work since I'm not connecting to a database. Can somebody recommend either an alternative or a tutorial for how to use DataGridView that's simple and understandable?


7 Years
Discussion Span
Last Post by sknake

Can you post the code for your dictionary so I can use it to generate an example? The easy way would be to use the Dictionary<string, Table> if the Table datatype is DataTable. Likewise for the child collections you could go to the parent collection and use the datatable.

Make sure you have all definitions so we can compile this code. It would be handy to have some sample data as well.


Thanks, I didn't actually realize there was a DataTable type. C# has a much wider set of complex data types than I'm used to from, say, Python.

I'll have to do a bit of rewriting later on today. Then I'll let you know if I need more help or not.


Oh yes, use data tables for sure :). You can also use a DataSet which is comprised of many DataTables and add constraints to relate them. I do not know if that fits your scenario here, but here is sample code of some things you can do with these classes:

_ds* is DataSet, _dt* is DataTable

_ds = new DataSet("dsAlarms");
      _ds.EnforceConstraints = false;



      gridControl1.DataSource = _ds.Tables["Alarms"];

Then in the grid I have it set up where you can expand the parent row and a child grid view will open up under the row.


Thanks for posting your code sknake, it's really helpful for a newbie like me to see how these things are used :).

Just a side question, Is there a way to bind the list of tables in a dataset to the list in a listbox?


I don't think so. You can easily iterate the tables in the dataset and add the items to the listbox manually though.

private void button1_Click(object sender, EventArgs e)
      DataSet ds = new DataSet("dsTest");
      ds.Tables.Add(new DataTable("dt1"));
      ds.Tables.Add(new DataTable("dt2"));
      ds.Tables.Add(new DataTable("dt3"));
      ds.Tables.Add(new DataTable("dt4"));

      //You can access the tables by ds.Tables["name"]
      foreach (DataTable dt in ds.Tables)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.