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();
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()); } }
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
thanks i had a slow moment, doing to many tasks at one time froze my brain
i was checking for null, but i was checking for null on the wrong propertie or object. thanks
review below.
Correct:
(this.ultraOptionSetFilterBy.CheckedItem != null)
do something
)
Not Correct:
(this.ultraOptionSetFilterBy.CheckedItem.DataValue != null) Error