Hey guys, how can I bind the combo to a List<T>
if I add the columns manually to the WinCombo and then set the datasource to the list, it will ignore the columns I added and display all the properties of the list as columns.
I thought I could use the UltraDataSource but I couldn't figure out how to populate it since the following is not possible:
ultraDataSource1.DataSource = List
so far this is what I'm doing:
foreach (ValidvaluesBO vvl in vvlList){ ultraDataSource1.Rows.Add(new object[{vvl.Code , vvl.Name} ); }
combo.DataSource = ultraDataSource1 ;
but I was wondering if there is some other way of doing this.
any ideas?
thanks !
There you go, that's the answer I was looking for.
Thanks for your help !
You wouldn't. The Add method on the columns collection exists in order to allow you to add additional unbound columns. You cannot add a bound column. When you bind the control, it automatically creates all of the bound columns it needs based on the data source. You canot remove a bound column, either, you can only hide it.
The wincombo has a way to progamatically add columns:
combo.DisplayLayout.Bands[0].Columns.Add("Column1");
However, as I mentioned on my first post, every time I set the datasource to a list of objects, the wincombo will display every single property instead of those I defined previously.
You are suggesting to hide those extra columns, which is an option.
I just have a simple question: why would I then add those columns if eventually the columns will change whenever I set a datasource.
I'm assuming I'm doing something wrong. I guess there should be a way I can make the wincombo persist the column definition set by using:
combo.DisplayLayout.Bands[0].Columns.Add("Column2");
What you do is set the Hidden property on the columns you want to hide. A good place to do this is in the InitializeLayout event of the combo.
Mike Saltzman"]You started off by saying that you want to hide some columns at design-time. So I suggested you do it at run-time and pointed you to a KB article that shows how to do it at design-time.
I started off by saying I was assigning a datasource a design time but when I tried to populate the combo with a list, it was displaying all the properties of the list and not the columns that I added at design time. So I thought I could live with that and hide the columns on the fly. Your tip about the InitializeLayout solves the problem.
Mike Saltzman"]But now you are saying you don't know the layout at design-time.
The first was a test. The goal is to set the columns at run time.
Mike Saltzman"]If you don't know the layout, how can you hide the columns?
I don't know it at design time, but I will do at runtime. The same combo box will be used to display data from differentes tables.
So let me restate my question. How can you set the columns to be displayed on a WinCombo programatically?