Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to bind the ComboBox which is in a ListView using collection

How to bind the ComboBox which is in a ListView using collection

Scheduled Pinned Locked Moved WPF
wpfwcftutoriallearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DavJes
    wrote on last edited by
    #1

    Hi, I have listView, which has a GridView Column ,having DataTemplate which has ComboBox, I m binding the listview's Colums using a collection , but this combo alone with another collection . But its not working . //resource ... code : namespace N { public class NameList : List { public NameList() { //this.Add("Name"); //this.Add("Name1"); } } public partial class Window5 : Window { public NameList pp { get;set; } public Window5() { this.InitializeComponent(); pp = new NameList(); pp.Add("dfgdf"); pp.Add("ggf"); } } } Here if i hard code values inside consturctor its working , if i create object of this class and add items to it. its not binding. pl let me know how to bind the object of the colletion to combo thanks

    I 1 Reply Last reply
    0
    • D DavJes

      Hi, I have listView, which has a GridView Column ,having DataTemplate which has ComboBox, I m binding the listview's Colums using a collection , but this combo alone with another collection . But its not working . //resource ... code : namespace N { public class NameList : List { public NameList() { //this.Add("Name"); //this.Add("Name1"); } } public partial class Window5 : Window { public NameList pp { get;set; } public Window5() { this.InitializeComponent(); pp = new NameList(); pp.Add("dfgdf"); pp.Add("ggf"); } } } Here if i hard code values inside consturctor its working , if i create object of this class and add items to it. its not binding. pl let me know how to bind the object of the colletion to combo thanks

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      You're adding elements to the wrong list. You need to get a reference to "myList" and add the elements to that, not create a new one in the code-behind. Check out the FindResource function, and use that to get "myList".

      Proud to have finally moved to the A-Ark. Which one are you in?
      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

      D 1 Reply Last reply
      0
      • I Ian Shlasko

        You're adding elements to the wrong list. You need to get a reference to "myList" and add the elements to that, not create a new one in the code-behind. Check out the FindResource function, and use that to get "myList".

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        D Offline
        D Offline
        DavJes
        wrote on last edited by
        #3

        Thanks for the info, It worked after I use FindResource. But I have one more trouble, I have a button called ResetAll, Onclick of it, should reset all the Combo indexs to 0 or -1 in the listview. As the combo is built added part of datatemplate in each listview item. Can u throw me a way to do this. pl find the reference code below Xmal : Code : Namespace N { public class NameList : List { public NameList() { } } public class Window1 { Window1() { ObjectDataProvider objectDataProvider = this.TryFindResource("myList") as ObjectDataProvider; NameList nameList = objectDataProvider.Data as NameList; AddItemsToCombo(ref nameList );//this adds items to combo from webserivce } On_ResetButtonClick() { //How do I reset the comboItems of each listview item. } } Thanks in adavance

        I 1 Reply Last reply
        0
        • D DavJes

          Thanks for the info, It worked after I use FindResource. But I have one more trouble, I have a button called ResetAll, Onclick of it, should reset all the Combo indexs to 0 or -1 in the listview. As the combo is built added part of datatemplate in each listview item. Can u throw me a way to do this. pl find the reference code below Xmal : Code : Namespace N { public class NameList : List { public NameList() { } } public class Window1 { Window1() { ObjectDataProvider objectDataProvider = this.TryFindResource("myList") as ObjectDataProvider; NameList nameList = objectDataProvider.Data as NameList; AddItemsToCombo(ref nameList );//this adds items to combo from webserivce } On_ResetButtonClick() { //How do I reset the comboItems of each listview item. } } Thanks in adavance

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          You shouldn't be trying to edit the combo boxes directly, especially if they're in a DataTemplate. Instead, go to whatever they're bound to, and set THAT to null. If your binding is correct, the combos will automatically update themselves. Remember that either the bound object needs to implement INotifyPropertyChanged, or the bound property has to be a DependencyProperty... Otherwise the binding won't be triggered.

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups