Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Wednesday, June 30, 2010

WF list/combo value and representation

If your list/combobox just has strings as items, you can get the selected value with .Text . But this restricts you to displaying and storing the same item (ie you can't have 'International Electromatics' in the display and be storing 'IE' behind the scenes).

To do the latter you need to define a class which defines methods for getting the value (IE) and the representation (International Electromatics) of its instances. Then you set the DataSource of the control to be an ArrayList of these objects. Finally you set the DisplayMember and ValueMember properties of the control to the names of the the class methods.

Now, the control's SelectedValue property will be the ValueMember of the object that is currently selected. NB that SelectedValue appears to return an object which you must cast to a string, not a string per se.

Fragmentary example:

ArrayList Availabletests = new ArrayList();
...
Availabletests.Add( new UnitTest( 1, "tryparse datetime(p)" ) );
Tests.DataSource = Availabletests;
Tests.DisplayMember = "Representation";
Tests.ValueMember = "Value";
...
Output.Text = Tests.SelectedValue.ToString();
...

public class UnitTest {
/*protected*/ private int number;
/*protected*/ private string description;

public UnitTest (int num, string desc) {
this.number = num;
this.description = desc;
}

public string Value {
get { return number.ToString(); }
}

public string Representation {
get { return number.ToString() + ": " + description; }
}

}


Properly explained example with US states in ListControl.DataSource

As always with .NET there's a lot of typing but I admit this is a nice flexible, modular way to go about it.

Thursday, June 17, 2010

null and not in

a not in (...) will exclude null values of a. Probably not what you want.

Followers

Blog Archive