Hi,
I add two columns in ultragrid named "COL1","COL2" when form Load, and then I binding a datatable dt with only one column named "COL1" ,and SetDataBinding(dt, Nothing, True). at that time the grid showed data perfectly. and then I create another datatable dt2 with only one column name "COL2", and SetDataBinding(dt2, Nothing, True). Unfortunately, the grid lost the COL1, Why? How to always keep the columns that defined in the Form Load
I use win7/.NET 2010/Vol2013.1
Cheers!
This won't work. The grid can't maintain the data structure once you bind it more than once at run-time. When you bind the grid at run-time, it tries to maintain the data structure from design-time, but it marks the design-time structure specially for this purpose. You can't do it at run-time.
If you want to have unbound columns in the grid like this, then I recommend using the InitializeLayout. Examine the existing columns and then add unbound columns for any extra columns you want that are not in the data source.
Hi,Mike,
I'm a new man in win ultragrid, could you give me some sample code for Initializelayout according to my request. thanks!
Jason
Hi, Mike
It works well! Thanks.
Hi Jason,
Okay, I attached a quick little sample here for you. Click the buttons at the top to bind the grid to a DataTable with Column0, Column1, or both.
The InitializeLayout event check for the existence of each column and whichever column does not exist, it adds an unbound column for it.
Yes, you understand very correct!
I'd be happy to whip up some sample code for you, but before I do that, I just want to make sure I am clear on what you want.
Basically, you want the grid to always show the same two columns and you will be binding the grid to a data source that only has one or the other (or possibly both). Is that right?
If so, then basically what you will want to do is examine the columns inside the InitializeLayout event and check to see if it already exists. If it does, no problem, if it doesn't then you will add a new unbound column.
Does that sound right?