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 !
Hi,
The easiest thing to do is set the DataSource and then use the InitializeLayout event of the combo to hide the columns you do not want to see.
If you want to set up the layout at Design-time, before you bind, then you have to do this the same way you would in the grid. Here's a KB article that explains how:
HOWTO:How can I define columns in the grid at Design-time and bind them at run-time so that some fields of the data are excluded from the grid?
Thanks for your reply.
Mike Saltzman"]The easiest thing to do is set the DataSource and then use the InitializeLayout event
Are there other solutions ?
I kind of like the idea of hiding unnecessary columns, so there is no way to programmatically define the columns huh?
Mike Saltzman"] If you want to set up the layout at Design-time
I don't know the layout at design time.
I don't understand what you are asking here, then. 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. But now you are saying you don't know the layout at design-time. If you don't know the layout, how can you hide the columns?
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?
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.