Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
830
Grid "cloning"
posted

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.

Parents
  • 37774
    Verified Answer
    posted

    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

Reply Children
No Data