I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView is actually a tab in a TabControl element.
I gave it 5 colums which need to be filled up with elements from a costum Object i made.
It's basically a small library application which contains a main class and several classed derived from it. They all have a ToString() method which represents the data as a string of keywords containing the values needed for me to fill up the datagridview.
I only need the first 5 though, some objects will have up to 12 keywords. Currently, Whenever I add an object, the datagrid doesn't fill itself, instead it adds an amount of columns equall to the amount of keywords the specific object has.
What i'm currently doing is this:
public void libDataGrid_Click(object sender, EventArgs e)
{
if(this.manager.Lib.LibList[0] != null)
{
libDataGrid.DataSource = this.manager.Lib.LibList;
libDataGrid.Refresh();
}
}
this.manager.Lib.LibList
returns and ArrayList, in which all objects are stored. The ArrayList can contain elements of all derived classes, but since they are all connected, the string representation will always contain the elements I need to fill up the grid.
I don't see how I can filter only the first five and them have them put in the correct colums.
And another thing. Currently I can only refresh the DataGridView by clicking it. It should change on when I switch to it switch to its specific tab on the Tabcontrol I mean.
I tried adding an argument for SelectedIndexChanged, but that does nothing really... Or at least, it doesn't appear to do anything.
What I mean is I commented out the code above and added this instead:
public void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
libDataGrid.DataSource = this.manager.Lib.LibList;
libDataGrid.Refresh();
}
This refreshes it everytime the tab is changed, no matter to which one. I had to remove the if-statement, since it gave me an Exception. Probably because the length of the ArrayList isn't set on initialisation.