Einzelnen Beitrag anzeigen

Elvis

Registriert seit: 25. Nov 2005
Ort: München
1.909 Beiträge
 
Delphi 2010 Professional
 
#2

Re: "Master-Detail" Databinding von Listbox nach T

  Alt 31. Jan 2007, 18:35
Hier mal'n Bleistift:
Delphi-Quellcode:
uses
  System.Collections.Generic,
  System.Windows.Forms;

type
  SampleClass2 = class
  public
    property SomeValue : String;
  end;

  SampleClass1 = class
  public
    property SomeValue : String;
    property Content : SampleClass2 := new SampleClass2(SomeValue := 'noch nix drin'); readonly;
  end;

    
class method ConsoleApp.Main;
begin
  var myForm := new Form();
  
  myForm.SuspendLayout();
  var lb := new ListBox();
  var tb := new TextBox();
  
  tb.Dock := DockStyle.Top;
  lb.Dock := DockStyle.Fill;
  
  var list := new List<SampleClass1>(3);
  list.Add(new SampleClass1(SomeValue := 'A'));
  list.Add(new SampleClass1(SomeValue := 'B'));
  list.Add(new SampleClass1(SomeValue := 'C'));
  
  lb.DataSource := list;
  lb.DisplayMember := 'SomeValue';
  
  tb.DataBindings.Add('Text', list, 'Content.SomeValue');
  
  myForm.Controls.AddRange([lb, tb]);
  
  myForm.ResumeLayout();
  
  Application.Run(myForm);
end;
Robert Giesecke
I’m a great believer in “Occam’s Razor,” the principle which says:
“If you say something complicated, I’ll slit your throat.”
  Mit Zitat antworten Zitat