C# window application checkboxlist selection mode one not working -
i have window application. now, @ run time adding 1 page & checkboxlist inside of page.
for code is:
form inputbox = new form(); inputbox.formborderstyle = system.windows.forms.formborderstyle.fixeddialog; inputbox.clientsize = size; inputbox.text = "doc selection"; inputbox.startposition = formstartposition.centerscreen; inputbox.controlbox = false; system.windows.forms.checkedlistbox doctypechklist = new checkedlistbox(); doctypechklist.location = new system.drawing.point(15, 10); doctypechklist.font = new system.drawing.font("microsoft sans serif", 12f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((byte)(0))); doctypechklist.items.add("b"); doctypechklist.items.add("p"); doctypechklist.items.add("other"); doctypechklist.selectionmode = selectionmode.one; inputbox.controls.add(doctypechklist);
now, @ run time user can check multi check box...i want @ time 1 checkbox should check instead of multi....i gave selection mode "one" ..
can let me know.what missing????
thanks
checkedlistbox
allows user check multi-checkboxes , that's purpose of designing control. selectionmode
indicate can select 1 or more items (an item considered selected if it's hightlighted not checked). work-around have add code handle itemcheck
event. mechanism simple.
int lastcheckedindex = -1; //itemcheck event handler checkedlistbox1 private void checkedlistbox1_itemcheck(object sender, itemcheckeventargs e) { if (e.index != lastcheckedindex) { if(lastcheckedindex != -1) checkedlistbox1.setitemcheckstate(lastcheckedindex, checkstate.unchecked); lastcheckedindex = e.index; } } //to register event checkedlistbox1.itemcheck += checkedlistbox1_itemcheck;
Comments
Post a Comment