Get the item in a listbox that was unchecked using Click Event C# Winforms -


i created winforms application in c# vs2008. listbox componentone list box. has checkedlistbox. (each item has checkbox user can select.) created click event when user selects item clicking checkbox, runs query database retrieve data. works fine. need identify when user unchecks selection.

when uncheck selection lstbxbatchnumbers.selectedtext retrieves last selected item.
how can item unchecked?

the click event has parameters (object sender, eventargs e) listbox not specific row clicked.

is there way this? below click method:

private void c1lstbxbatchnumbers_click(object sender, eventargs e) {     int tiselectedbatchnumbercounter = 0;      int tibatchnumbercolumn = 0;     string tstrdelimitbatchnumbers = "', '";     string tstrbatchnumberlist = string.empty;     datatable tdtbatchdetails = new datatable();      if (dscasepick.tables["selectedbatchnumbers"].rows.count > 0)     {         dscasepick.clear();     }      //here need find out if item clicked unchecked?       //check if there batch number in cancel pick table not selected     //if there is, give user option add list , keep rows or remove rows cancel pick table     string tstrbatchnumberincanceltable = string.empty;       string tstruncheckedbatchnumber = e.tostring();     foreach (datarow cancelrow in dtcancelpick.rows)     {         string tstrcancelbatchnumber = cancelrow["batchnumber"].tostring();         if (c1lstbxbatchnumbers.selectedtext.equals(tstrcancelbatchnumber))         {             tstrbatchnumberincanceltable = tstrcancelbatchnumber;             break;         }     }     if (!string.isnullorempty(tstrbatchnumberincanceltable))     {         string tstrerror = "the batch number, " + tstrbatchnumberincanceltable + ", has been unselected , has values in cancel pick grid cancelled.\n";         tstrerror += "do want continue , have these picks removed cancel pick grid?";         dialogresult answer = messagebox.show(tstrerror, "cancel picks not selected", messageboxbuttons.yesno, messageboxicon.error);         if (answer == dialogresult.yes)         {             //remove batch number cancel data table             string tstrfilter = "batchnumber = '" + tstrbatchnumberincanceltable + "'";             datarow[] rowstodelete = dtcancelpick.select(tstrfilter);             foreach (datarow row in rowstodelete)             {                 //remove button grid                        foreach (hostedcontrol hosted in alremovecasepickbtns)                 {                     button ctl = hosted._ctl button;                     if (ctl.tag.tostring().equals(row["workreference"].tostring()))                     {                         ctl.dispose();                         break;                     }                 }                 dtcancelpick.rows.remove(row);            }            dtcancelpick.acceptchanges();            c1flxgrdcancelpick.refresh();        }        else        {            //check batch number in list            int tiindex = c1lstbxbatchnumbers.findstringexact(tstrbatchnumberincanceltable);            c1lstbxbatchnumbers.setselected(tiindex, true);        }     }      //does more stuff ... } 

the initialization of listbox control:

 //          this.c1lstbxbatchnumbers.additemseparator = ';';         this.setcaption(this.c1lstbxbatchnumbers, "batch numbers");         this.c1lstbxbatchnumbers.captionheight = 25;         this.c1lstbxbatchnumbers.columncaptionheight = 25;         this.c1lstbxbatchnumbers.columnfooterheight = 25;         this.c1lstbxbatchnumbers.columnheaders = false;         this.c1lstbxbatchnumbers.datamode = c1.win.c1list.datamodeenum.additem;         this.c1lstbxbatchnumbers.deadareabackcolor = system.drawing.systemcolors.controldark;         this.c1lstbxbatchnumbers.defcolwidth = 90;         this.c1lstbxbatchnumbers.font = new system.drawing.font("microsoft sans serif", 9f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((byte)(0)));         this.c1lstbxbatchnumbers.images.add(((system.drawing.image)(resources.getobject("c1lstbxbatchnumbers.images"))));         this.c1lstbxbatchnumbers.itemheight = 25;         this.c1lstbxbatchnumbers.location = new system.drawing.point(363, 12);         this.c1lstbxbatchnumbers.matchentrytimeout = ((long)(2000));         this.c1lstbxbatchnumbers.name = "c1lstbxbatchnumbers";         this.c1lstbxbatchnumbers.rowdivider.style = c1.win.c1list.linestyleenum.none;         this.c1lstbxbatchnumbers.rowsubdividercolor = system.drawing.color.darkgray;         this.c1lstbxbatchnumbers.selectionmode = c1.win.c1list.selectionmodeenum.checkbox;         this.c1lstbxbatchnumbers.size = new system.drawing.size(130, 164);         this.c1lstbxbatchnumbers.tabindex = 13;         this.c1lstbxbatchnumbers.tabstop = false;         this.c1lstbxbatchnumbers.text = "batch numbers";         this.c1lstbxbatchnumbers.click += new system.eventhandler(this.c1lstbxbatchnumbers_click);         this.c1lstbxbatchnumbers.propbag = resources.getstring("c1lstbxbatchnumbers.propbag"); 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -