I am trying to bind data to my DataGridView. (However, this is the easy explanation.)
Background on what I am trying to accomplish:
I have a rather large program here. This part of the code uses a DataGridView to display the data I have read and parsed (from another program through an Interop (not sql)). I bind the data using something like this:
private DataTable ConvertListToDataTable(List<List<object>> list)
{
DataTable table = new DataTable();
for (int i = 0; i < MyList.Count; i++)
{
table.Columns.Add(MyList[i], typeof(string));
}
table.Columns.Add("", typeof(object));
// Add rows data
List<object[]> tObj = new List<object[]>();
for (int i = 0; i < list.Count; i++)
{
tObj.Add((object[])(list[i].ToArray()));
}
for (int i = 0; i < list.Count; i++)
{
table.Rows.Add(tObj[i]);
}
return table;
}
And it binds to the DataGrid with:
DataTable table2 = new DataTable();
table2 = ConvertListToDataTable(myList);
bindingSource1.DataSource = table2;
dataGridView1.DataSource = bindingSource1;
This works perfectly fine. The new problem is, MyList is no longer of type object. The data I read from the (Interop)source has both object
and object[]
in the same fields, but depends on which item it is reading. The data stored can be well over 1000 entries and the location of these internal lists (object[]) are not static.
I created a custom class to hold this data, it looks like this:
public class DataGridDataObject
{
public object Data;
public object[] DataList;
public enum type { single, multi, none };
public DataGridDataObject.type Type;
public DataGridDataObject()
{
Data = null;
DataList = null;
Type = type.none;
}
}
The ConvertListToDataTable(List<List<object>> list)
changes to ConvertListToDataTable(List<List<DataGridDataObject>> list)
What I need to accomplish and hope can be done is within the DataGridView. When the enum.type of the object is single, make the cell in this row a TextBoxCell, when the enum.type is multi, make the cell a ComboBox.
I have read and been able to change an entire column to a combobox at creation but not every item is a list (which would require a combobox).
Here is the basic idea I am hoping to accomplish.
Is this even possible?
A side note, this is not sql, asp.net or a web based program.
I am using .net3.5
Thank you!