Coming back to the original problem, you can also fill a listbox or combobox by setting the datasource to any object that implements the interface IList. I had the problem,that I wanted the ValueMember property differently set to the DisplayMember. With the collections Add() method this is not possible. So I defined a simple class: internal class clsName { private string _longname; private int _uid; public string LongName {get {return _longname;} set {_longname = value;}} public int UID {get {return _uid;} set {_uid = value;}} public clsName (string lname, int uid) { _longname = lname; _uid = uid; } } and filled the combobox with an arraylist (the parameters come from a xml file): [...] _arrNames.Add(new clsName(nav2.Value,System.Convert.ToInt32(iterator.Current.GetAttribute("UID",nav.NamespaceURI)))); [...] The combobox datasource can then be set to the arraylist and the members to the appropriate custom class properties. [...] cb.DataSource = _arrNames; cb.DisplayMember = "LongName"; cb.ValueMember = "UID"; [...] That's all and the list is filled with the strings plus the value is set to what I need in the combobox event handler later in the application. Wolfgang
W
Wolfgang Loder
@Wolfgang Loder
Posts
-
Overriding ToString -
friend classes?Alexandru, a similar construct to friend is the internal keyword, which allows access from within the same assembly, but not from outside. Wolfgang
-
ArraysBo, I can see two mistakes: (1) referring to '7.5.10.2 Array creation expressions' in the C# online reference you cannot instantiate the sub-arrays, because the initial value of the first array is null. But in any case this would be an array of new byte [count] []. You try to create a subarray, where no array is created and initiated: new byte [][count] <- this can never work, because the compiler doesn't know how many sub-arrays (i.e. memory) must be initiated. (2) don't cast to uint, use System.Convert.ToUInt32. Hope this makes your year :cool: Wolfgang