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
OK, to add more info to this. do one of the following things:
this.DataMember = sDisplayField; //Where sDisplayField is the field I want displayed in the dropdown this.DataSource = dt; //dt is the DataTable to which I am bindingOR this.SetDataBinding(dt, sDisplayField, false, false);
Neither of the above two scenarios work and I get an "Object reference not set to an instance of an object." ERROR.
However, if I don't assign to the DataMember property, the binding works but I get to see the WHOLE table in the dropdown at run-time.I only want to see ONE named field. And yes, I have checked that the field is named correctly when assigning to the DataMember as I can also assign to DisplayMember without errors.
URGENT, please help!
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.
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 :-)
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.
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...