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
2730
Ultra Option Set
posted

When setting "this.ultraOptionSetFilter.CheckedIndex = -1;" to -1, the option set goes null,

so then when i try to set the value to a property or variable i get an error. i am simply trying to clear the option set first then after I do a certain thing, then when I come back around to it, I want ot be able to reselect with out getting the error object has not been set to an instance.

I am going to give an quick example of what I am doing below.

Example:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

private void ultraOptionSetSearch_ValueChanged(object sender, EventArgs e)

{

 

 

 

if (this.ultraOptionSetSearch.CheckedIndex != -1)

{

 

 

 

 

 

 

////Clear ultraOptionSetFilterBy default if user have selected another item type is selected.

this.ultraOptionSetFilterBy.CheckedIndex = -1;

}

}

Now if re execute the logic below the second time, I get a error

Item =

 

this.ultraOptionSetFilterBy.CheckedItem.DataValue.ToString();

Parents
No Data
Reply
  • 53790
    Verified Answer
    posted

    Hello Keith,

    if I understood your scenario well, I suppose that mentioned behavior is expected, because when you set property to

    -  this.ultraOptionSetFilterBy.CheckedIndex = -1;  your  ValueChanged() event fired again. After that your object ultraOptionSetFilterBy.CheckedItem does not exist (the result  is null )  and you could not be able to get DataValue from NULL object and that way you get this error.

    Maybe you could modify your code to get DataValue only when the object is not null. For example:

    private void ultraOptionSet1_ValueChanged(object sender, EventArgs e)

    {

        if (this.ultraOptionSet1.CheckedIndex != -1 )

        {

            this.ultraOptionSet1.CheckedIndex = -1;

            Debug.WriteLine(this.ultraOptionSet1.CheckedItem.DataValue.ToString());

        }

    }

    Let me know if you think that I misunderstood your scenario or if you have any questions.

    Regards

     

     

Children