c# - How to stop a ListBoxItem from being selected if the data related to the previous one is incorrect? -
i have listbox
when clicked displays data user. if user enters invalid data , click item in list want prevent listboxitem
clicked being selected. however, listboxitem_selected
event firing after listboxitem
being selected, don't know how stop next list box item being selected.
in listboxitem_selected
event, i'm validating data point it's late.
simply executing
((listboxitem)this.listbox.items[previousindex]).isselected = true;
or
this.listbox.selectedindex = previousindex;
does not work, i.e. next list item still selected.
how can prevent next item being selected if data entered invalid?
so best way bind listbox enabled bool in code.
something this
public bool enabledornot { get; set; } <listbox isenabled={binding enabledornot}>...
then when validation on first input can set bool , enable or disable needed.
another way use validationrules. know use these in our code @ work arcane me understand. know somehow validate before else takes place. built in .net feature
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validationrules.aspx
Comments
Post a Comment