Listbox: "Could not bind to the new display member"



Hi all,
I tried to create and fill a listbox specifying DataSource,
DisplayMember and ValueMember properties. But I got a error "Could not
bind to the new display member".
Then I found an example in Delphi help (only for VB or C++ for some
reason!),
translated it to Pascal and got the following code:


type
USState = Class
Private
myShortName :String;
myLongName :String;

Public
constructor create(strlongName :String; strShortName :String);

Public
property ShortName:string read myShortName;
property LongName:string read myLongName;
End;

type
ListBoxSample3 = Class (System.Windows.Forms.Form)
ListBox1 :ListBox;
textBox1 :TextBox;
constructor create;
End;
????????????????????

implementation

constructor USState.Create(strlongName :String; strShortName :String);
begin
inherited create;
Self.myShortName := strShortName;
Self.myLongName := strLongName ;
end;

constructor ListBoxSample3.Create;
var
USStates :ArrayList;
begin
inherited Create;
Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
Self.ClientSize := System.Drawing.Size.Create(292, 181);
Self.Text := 'ListBox Sample3';

ListBox1 := ListBox.Create;
textbox1 := TextBox.Create;

ListBox1.Location := Point.Create(24, 16);
ListBox1.Name := 'ListBox1';
ListBox1.Size := System.Drawing.Size.Create(232, 130);

textBox1.Location := Point.Create(24, 160);
textBox1.Name := 'TextBox1';
textBox1.Size := System.Drawing.Size.Create(40, 24);

Self.Controls.Add(ListBox1);
Self.Controls.Add(TextBox1);

USStates:= Arraylist.Create;
USStates.Add(USState.Create('Washington', 'WA'));
USStates.Add(USState.Create('West Virginia', 'WV'));

ListBox1.DataSource := USStates;
ListBox1.DisplayMember := 'LongName';
ListBox1.ValueMember := 'ShortName';
End ;


When I run this code, I get "Could not bind to the new display member.
Parameter name: NewDisplayMember" again!
The error happens on the last row: ListBox1.ValueMember :=
'ShortName';

If I comment the last row ListBox1.ValueMember := 'ShortName' then I
get idiotic window containing the list
Common.USState
Common.USState
Where real USStates values are?

Thank you,
Zina.
.



Relevant Pages

  • Re: S10 sshd X forwarding problem
    ... X11 display socket. ... Looks like the fix for CR 6684003 breaks sshd's ability to bind to a local ... if on the remote host I touch hostname6.lo0 I get the remote display. ...
    (comp.unix.solaris)
  • Re: S10 sshd X forwarding problem
    ... X11 display socket. ... Looks like the fix for CR 6684003 breaks sshd's ability to bind to a local ... if on the remote host I touch hostname6.lo0 I get the remote display. ...
    (comp.unix.solaris)
  • Re: S10 sshd X forwarding problem
    ... X11 display socket. ... Looks like the fix for CR 6684003 breaks sshd's ability to bind to a local ... if on the remote host I touch hostname6.lo0 I get the remote display. ...
    (comp.unix.solaris)
  • RE: Inserting subtotal rows into a datatable
    ... and then bind it onto a webform datagrid. ... the means how to bind the datatable to the grid may ... also change the display order since Only the raw "Rows" collection of the ... verify whether the actual order in the Rows collection is correct. ...
    (microsoft.public.dotnet.framework.aspnet)