Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
545
Ultracombo - SetInitialValue
posted

 

 

Can someone explain to me what's going on here...

I'm populating a grid based on a value selected in a stand alone UltraCombo.  When opening the form I would like to initialize the combo with the most common selection and thus populate the grid with data.

Performing SetInitialValue automatically calls the ValueChanged event - which is great.

If I designate my ultracombo to be of style "DropDown" the following code runs fine - meaning that, in the ValueChanged event, the value has a valid value.  However, if I simply change the style to "DropDownList" the ucChooseVendor.Value is null.

I had initially setup a bunch of forms with the style being DropDown (the default) but realized that the user could type text within the dropdown which I did not want - so I changed them to DropDownList style.

PS #1: Is there a way to have a DropDown style and yet prevent them from changing the list items (i.e., typeing) in the control?

PS #2: I also noticed that with the DropDown style, when I type bogus info into the combo the ucChooseVendor.Value is the value of the bogus data rather than say maybe null or -1.  In other words, why now all of a sudden, does the control want to return the DisplayMember vs the ValueMember?

All-in-all, somewhat confusing behavior in my opionion.

Thanks,

Mark

private void form1_Load(object sender, EventArgs e)

{

.....other code here....

ucChooseVendor.SetInitialValue(drv["VendorID"].ToString(), drv["Name"].ToString());

}

 

 

 

 

private void ucChooseVendor_ValueChanged(object sender, EventArgs

e)

{

....

 

 

 

 

 

DataTable dt = DataLayer.Vendors.GetGLAccountVendorItems(ucChooseVendor.Value.ToString()); // <= Value is Null here depending on style

....

 

 

 

 

)

Parents
No Data
Reply
  • 469350
    Offline posted

    In DropDownList mode, only values that exist on the list are valid. So my guess is that you are calling the method before you have populated the list and so the Value of the control is getting set to null because the Value you are trying to apply is not on the list.

    SetInitialValue is designed to circumvent this scenario a little bit, by delaying the application of the value until someone asks for it. But if you ask for the value when the event fires and this occurs before the list is populated, it won't work.

    There are a number of ways you could get around this. One way would be to populate the list first and then simply set the Value property on the control (you don't need to call SetInitialValue in that case).

    Another way would be to move the code that populate the grid into a method and cal that method both from the ValueChanged event of the Combo and also in the Form_Load or some similar event to force the loading of the grid with the default data you want.

Children