0

I have a check list box in wpf. With some email ids populated using public ObservableCollection<BoolStringClass> TheList { get; set; } method at runtime.

When user save the record the selecetd email ids are saved in database(123@gmail.com;456@yahoo.co.in;789@rediff.com).. and so on with comma separated.

Now when I want to reload the data on to controls from database, how can I keep checked the items stored in database ? In windows forms its easy to achieve this, but how this can be done in wpf?

ASh
  • 34,632
  • 9
  • 60
  • 82
  • Take a look at [this answer](https://stackoverflow.com/a/21193608/1187982). Perhaps that will answer your question. – Joshua Shearer Jan 21 '16 at 06:27
  • 1
    What is wpf stopping to you which you can perform with Winform? – Hari Prasad Jan 21 '16 at 06:27
  • Joshua, the answer u provided is for geting the selected item in listbox. – user5370906 Jan 21 '16 at 06:40
  • Joshua, the answer u provided is for geting the selected item in listbox. I want that I have a datatable with thosed items that are present in list box also. I am looking for something like this foreach( var o in listEmailsIds.Items) { string v = o.ToString(); if (emailID.ToString() == v) //emailID is from database { v.ischecked = true; } – user5370906 Jan 21 '16 at 06:46

1 Answers1

2

Better have the ObservableCollection of EmailItem and have string and IsSelected property. Bind the collection to check box list. And Set IsSelected based on whether they are saved in database

Mahesh Malpani
  • 1,782
  • 16
  • 27
  • 1
    This should go as comment, check the question. – Hari Prasad Jan 21 '16 at 06:29
  • 1
    @HariPrasad Why? Does this not answer the question? Admittedly, it would be better if this answer went into more depth (and maybe provided an example) but it *is* an answer. – Joshua Shearer Jan 21 '16 at 06:34
  • 1
    can you provide a piece of code or an example for I want that I have a datatable with thosed items that are present in list box also. I am looking for something like this foreach( var o in listEmailsIds.Items) { string v = o.ToString(); if (emailID.ToString() == v) //emailID is from database { v.ischecked = true; } – user5370906 Jan 21 '16 at 07:12
  • http://stackoverflow.com/questions/17381741/get-all-selected-items-from-wpf-checkbox-list-give-me-error This has example with datatable instead of class, but using same approach to add the IsChecked column to the datatable – Mahesh Malpani Jan 21 '16 at 08:47
  • Guys I am looking for similar as marked correct in the link below answer but in WPF C# for checklistbox http://stackoverflow.com/questions/9185770/programatically-check-an-item-in-checkboxlist-where-text-is-equal-to-what-i-want – user5370906 Jan 22 '16 at 11:37