Hi,
I would like to know how to limit the number of cols displayed when one clicks the UltraCombo "down" btn.
I bind the ctl to a DataTable, set the DisplayMember property to a col name from the bound table. Then I try to set the DataMember property to a col name from the bound table too, but get an "Object not set to ....blah blah" error.
If I don't set the DataMember property, all works BUT the WHOLE table displays when I select the "down" on the control @ runtime.I only want to display one of the cols.
Can I do that on the UltraCombo AND remain bound to the whole DataTable?
I don't want to use the UltraComboEditor as I don't seem to be able to adjust the width of the list displayed...
Thanks
Would this help you? Columns index is zero based so 0 is column 1, 2 is column 3, etc.
cboUsers.DisplayLayout.Bands[0].Columns[2].Hidden = true;
cboUsers.DisplayLayout.Bands[0].Columns[4].Hidden = true;
cboUsers.DisplayLayout.Bands[0].Columns[6].Hidden = true;
Hi Mike, thanks for the advice. I will try this now.
Like I said before, this control will display data from any one of many different tables. I created an enum property on the control for the developer to select the table it is to show. Once the datasource is set, I fire a method to "switch case" on the enum property values and hide the appropriate cols depending on the table.
Anyway, I WILL try what you've suggested and see if that is easier or better...
THANKS
I'm not sure I follow why you can't use InitializeLayout. This event fires precisely when you need it to fire, right after you set the data source on the control. So at that point, you will know what data source you are using and which columns to hide. You will need to set the ValueMember and mayeb the DisplayMember properties of the combo based on the data source, as well.
I guess you don't HAVE to use InitializeLayout. You could simply set the DataSource on the combo and then immediately loop thruogh the columns right there in the same method. InitializeLayout is just convenient.
Mike, thanks for the tips!
I don't think the InitializeLayout would help.
I have inherited the UltraCombo control and added a couple of enum properties for the other developers to set when they drop the custom-control on a form.
When that form runs, the customized control hits the db according to the enum properties set at design time. Each of the tables are different with different fields etc. I cannot specify which to hide or not as the layout won't be known until the control is bound to the DataTable. Only THEN will the control "know" what fields it has and I can write a method to hide/show cols accordingly I guess.
I just don't see how to tell it to hide cols...but judging by your recommendation on using the InitializeLayout event, maybe I'll create a different layout for each known table and apply that according to the enum values selected by the developer...
If you can think of anything else, that would be most helpfull. Now I need to figure out what to do with layouts :-)
DataMember is not intended to be used to specify a single field. DataMember is only needed when you are binding to a data source that contains multiple tables or list and you want to specify which one to use. Since you are binding to a DataTable, setting DataMember does not make sense and you should leave it null.
If you want to hide certain columns on the list, then you should use the Hidden property on the column. A good place to do this is in the InitializeLayout event.