How to bind Mysql database With Checkbox items in Listbox in C# WPF? -
i have listbox contains checkboxes in datatemplate.the checkbox items symbolize authorities of users.and authorities located @ level field in database numeric variables(0 21).but on ui,we see names of authorities(21 authority names).i added names hand behind code @ createcheckboxlist method.i want bind names , values in database , display values checkboxes in listbox due numeric values @ database.how can that?
thats screenshot of level field of database:
thanks answers in advance..
xaml code
<stackpanel> <listbox name="lstuserdefination" scrollviewer.verticalscrollbarvisibility="auto" selectionmode="multiple" height="330"> <listbox.itemtemplate> <datatemplate> <listboxitem> <checkbox name="chkuser" content="{binding authorityname}" tag="{binding authorityvalue}" ischecked="{binding ischecked}"/> </listboxitem> </datatemplate> </listbox.itemtemplate> </listbox> </stackpanel>
c# code
public partial class userdefinationedit : window { public observablecollection<authority> authoritylist { get; set; } public int sayi; public userdefinationedit() { initializecomponent(); createcheckboxlist(); lstuserdefination.itemssource = authoritylist; } public void createcheckboxlist() { authoritylist = new observablecollection<authority>(); authoritylist.add(new authority() {authorityvalue = 0, authorityname = "0 - ********" }); authoritylist.add(new authority() { authorityvalue = 1, authorityname = "1 - *********" }); authoritylist.add(new authority() { authorityvalue = 2, authorityname = "2 - *********" }); authoritylist.add(new authority() { authorityvalue = 3, authorityname = "3 - *******" }); authoritylist.add(new authority() { authorityvalue = 4, authorityname = "4 - *******" }); authoritylist.add(new authority() { authorityvalue = 5, authorityname = "5 - *********" }); authoritylist.add(new authority() { authorityvalue = 6, authorityname = "6 - ********" }); . . . . this.datacontext = this; } private void btnunselectall_click(object sender, routedeventargs e) { foreach (var in authoritylist) { a.ischecked = false; } } private void btnselectall_click(object sender, routedeventargs e) { foreach (var in authoritylist) { a.ischecked = true; } } } public class authority : inotifypropertychanged { private string authorityname; private int authorityvalue; private bool ischecked; public string authorityname { { return authorityname; } set { authorityname = value; notifypropertychanged(); } } public int authorityvalue { { return authorityvalue; } set { authorityvalue = value; notifypropertychanged(); } } public bool ischecked { { return ischecked; } set { ischecked = value; notifypropertychanged(); } } public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string propertyname = "") { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } }
}
Comments
Post a Comment