How to bind the ComboBox which is in a ListView using collection
-
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
-
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
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) -
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)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
-
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
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)