For a purpose of Copy to clipboard or export to excel, I need to create a grid and set it's data source from a DataTable.
The problem I'm facing is that after I do: ultraGrid.DataSource = dt then the ultraGrid.Rows.Count still return 0.
It's like the grid is ignoring my data source.
For the testings that I've done, I can make it use my data source only if I add the ultraGrid to the form (this.Controls.Add(ultraGrid).
This is off course not what I need.
How can I force the ultraGrid that I create on runtime to accept my data source?
Thanks.
Thanks, that also did the trick.
The thing is that I already tried that yesterday and adding a binding context did not help... this is because I first added the data source and then added the binding context.
Now I've added the binding context first and then the data source. In the case of added a parent form it doesn't matter when I add it (So it is probbaly added the binding context and also doing some other stuff).
Thank you both for your help.
Try setting the BindingContext of the grid to a new instance of the BindingContext class (i.e. ultraGrid.BindingContext = new BindingContext()). The grid needs this in order to be able to obtain the data through the .NET BindingManager. The reason that it works when it's part of the form's Controls collection is because the grid will obtain its BindingContext through the parent.
-Matt
Thanks m8, I'll try that tomorrow.
It's eccepting it, but since it has no display, rows are not being created. I tried some refreshing methods and saw that grid.Rows.ExpandAll(true) can do the work.