Reputation: 1899
I am trying to create dynamic table based on the bindingsource
. My datasource
is bind with the bindingsource
. So, How can I know number of columns beforehand while creating a table?
Or is there any other solution?
Upvotes: 0
Views: 1528
Reputation: 14059
Try to use the BindingSource.GetItemProperties
method.
For instance, let's assume that the following class represents a single table row (as well as a single BindingSource
item):
public class Item
{
public int A { get; set; }
public string B { get; set; }
}
Since it has two public properties, so the BindingSource
will have two columns.
List<Item> list = new List<Item>();
BindingSource bindingSource = new BindingSource { DataSource = list };
You can get the number of columns in it as follows:
int columnsCount = bindingSource.GetItemProperties(null).Count; // returns 2
Upvotes: 2