dbLookupCombobox可以显示多个字段记录
好象是在DataField或者listfield里输入多个字段值,中间用“;”号相隔,自己试一下吧想用Tcombobox自己实现也可以,麻烦一些的是如何在TCombobox中出现分隔符把各个字段值分开
这里有段代码,或许对你有所帮助
procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
strVal, strAll: String;
pos1, pos2: Integer;
rc: TRect;
arrWidth: Array [0..3] of Integer;
begin
Combobox1.Canvas.Brush.Style := bsSolid;
Combobox1.Canvas.FillRect(Rect);
// Die einzelnen Spalten müssen durch ';' getrennt sein
// the columns must be separated by ';'
strAll := Combobox1.Items[Index]; arrWidth[0] := 0;
arrWidth[1] := 100; // Width of column 1
arrWidth[2] := 200; // Width of column 2
arrWidth[3] := 300; // Width of colimn 3 // Zeichenbereich für erste Spalte
// Drawingrange for first column
rc.Left := Rect.Left + arrWidth[0] + 2;
rc.Right := Rect.Left + arrWidth[1] - 2;
rc.Top := Rect.Top;
rc.Bottom := Rect.Bottom; // Text für erste Spalte ausfiltern
// Get text for first column
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1);
// Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom); // Zeichenbereich für zweite Spalte
// Drawingrange for second column
rc.Left := Rect.Left + arrWidth[1] + 2;
rc.Right := Rect.Left + arrWidth[2] - 2; // Text für zweite Spalte ausfiltern
// Get text for second column
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1); // Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom); // Zeichenbereich für dritte Spalte
// Drawingrange for third column
rc.Left := Rect.Left + arrWidth[2] + 2;
rc.Right := Rect.Left + arrWidth[3] - 2; // Text für dritte Spalte ausfiltern
// Get text for third column
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1); // Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom);
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
end;
{example}
procedure TForm1.Button1Click(Sender: TObject);
begin
with Combobox1.Items do
begin
Add('first;second;third;');
Add('column1;column2;column3;');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Style := csOwnerDrawFixed;
end;
好象是在DataField或者listfield里输入多个字段值,中间用“;”号相隔,自己试一下吧想用Tcombobox自己实现也可以,麻烦一些的是如何在TCombobox中出现分隔符把各个字段值分开
这里有段代码,或许对你有所帮助
procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
strVal, strAll: String;
pos1, pos2: Integer;
rc: TRect;
arrWidth: Array [0..3] of Integer;
begin
Combobox1.Canvas.Brush.Style := bsSolid;
Combobox1.Canvas.FillRect(Rect);
// Die einzelnen Spalten müssen durch ';' getrennt sein
// the columns must be separated by ';'
strAll := Combobox1.Items[Index]; arrWidth[0] := 0;
arrWidth[1] := 100; // Width of column 1
arrWidth[2] := 200; // Width of column 2
arrWidth[3] := 300; // Width of colimn 3 // Zeichenbereich für erste Spalte
// Drawingrange for first column
rc.Left := Rect.Left + arrWidth[0] + 2;
rc.Right := Rect.Left + arrWidth[1] - 2;
rc.Top := Rect.Top;
rc.Bottom := Rect.Bottom; // Text für erste Spalte ausfiltern
// Get text for first column
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1);
// Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom); // Zeichenbereich für zweite Spalte
// Drawingrange for second column
rc.Left := Rect.Left + arrWidth[1] + 2;
rc.Right := Rect.Left + arrWidth[2] - 2; // Text für zweite Spalte ausfiltern
// Get text for second column
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1); // Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom); // Zeichenbereich für dritte Spalte
// Drawingrange for third column
rc.Left := Rect.Left + arrWidth[2] + 2;
rc.Right := Rect.Left + arrWidth[3] - 2; // Text für dritte Spalte ausfiltern
// Get text for third column
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
pos1 := Pos(';', strAll);
strVal := Copy(strAll, 1, pos1 - 1); // Text ausgeben
// Draw Text
Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
// Trennlinie zwischen Spalten zeichnen
// Draw separating line betwenn columns
Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
Combobox1.Canvas.LineTo(rc.Right, rc.Bottom);
strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
end;
{example}
procedure TForm1.Button1Click(Sender: TObject);
begin
with Combobox1.Items do
begin
Add('first;second;third;');
Add('column1;column2;column3;');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Style := csOwnerDrawFixed;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货