Listbox: "Could not bind to the new display member"
- From: ZinaLozhkina@xxxxxxxxx (Zina)
- Date: 22 Apr 2005 04:23:28 -0700
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.
.
- Prev by Date: smart home key and other delphi extensions
- Next by Date: Re: smart home key and other delphi extensions
- Previous by thread: smart home key and other delphi extensions
- Next by thread: Non-visual components shifting on save
- Index(es):
Relevant Pages
|
|