Jump to content
Sign in to follow this  
jeliey

Wpf : How To Tick Checkboxes Based On Selected Checkbox_Id In Database

Recommended Posts

need ur help :( Ada sapa2 x yg penah guna WPF? harap2 ada la yg boleh membantu... In my wpf, i have successfully saved the selected checkboxes in my database. But i got issue on how to display the checked checkboxes. Lets say there are 7 checkboxes in total, and user ticked 3 out of them. I was able to retrieve the Checkbox_id from database through webservice, but how to bind it to checkboxes? ni table yg aku save checkbox_id: User_ID : 1 Widget_ID : 1,2,3 It should only checked the selected id (1,2,3), but all i got is the whole checkboxes are checked. Please help me fix this...below is my code:

 

 xaml: xaml.cs: XDocument doc = XDocument.Parse(e.Result); 
var query = from i in doc.Descendants("ResultTable") select i; foreach (XElement item in query) { 
selectedWidget = item.Element("Widget_ID").Value; 
} 

for (Int32 i = LBWidget.Items.Count - 1; i >= 0; i--) { 

ListBoxItem item = LBWidget.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;

ContentPresenter myContentPresenter = FindVisualChild(item);

DataTemplate dataTemplate = myContentPresenter.ContentTemplate;

CheckBox chk = dataTemplate.FindName("chk", myContentPresenter) as CheckBox; 

if (selectedWidget != null) { chk.IsChecked = true; } 

}

Share this post


Link to post
Share on other sites

Hai jeliey, sebelum post code tersebut.. sila gunakan tag [ C O D E ] [ \ C O D E] untuk memudakan kami membaca kod anda...

By the way, check box ini berada didalam list view ke?

Share this post


Link to post
Share on other sites

Hai jeliey, 

 

Try buat macam ini...

 

 

if (selectedWidget != DBNull.Value) 

{

chk.IsChecked = true; 

} 

Gud luck and happy programming....:D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...