I have adapted the C# code from
http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx for a
data grid combo box column and added it to my data grid. I don't get an
error but the column is simply not displayed (but if I query
VisibleColumnCount I get 7, which means it *should* be there, the row height
is also visibly larger). Can anybody spot what I might be missing/doing
wrong? TIA.
// init
ts := DataGridTableStyle.Create;
dc1 := DataGridTextBoxColumn.Create;
dc2 := DataGridBoolColumn.Create;
dc3 := DataGridTextBoxColumn.Create;
dc4 := DataGridTextBoxColumn.Create;
dc5 := DataGridTextBoxColumn.Create;
dc6 := DataGridTextBoxColumn.Create;
dc7 := DataGridComboBoxColumn.Create;
ts.MappingName := 'ODM';
ts.AlternatingBackColor := color.WhiteSmoke;
// column 1 - ordinary text box:
dc1.MappingName := 'fld_odmID';
dc1.HeaderText := 'ID';
dc1.Alignment := HorizontalAlignment.left;
dc1.NullText := '';
dc1.Width := 45;
<snip - columns 2 - 6 are all text boxes>
// column 7 - the combo box:
SetLookupBinding(dc7.Combobx, 'fld_LastName', 'fld_ContactID',
ds.Tables['contact']); //see procedure below
dc7.HeaderText := 'Ansprechpartner';
dc7.Alignment := horizontalalignment.Left;
dc7.NullText := '';
dc7.Width := 150;
ts.PreferredRowHeight := dc7.Combobx.Height + 1;
ts.GridColumnStyles.Add(dc1);
ts.GridColumnStyles.Add(dc3);
ts.GridColumnStyles.Add(dc4);
ts.GridColumnStyles.Add(dc5);
ts.GridColumnStyles.Add(dc2);
ts.GridColumnStyles.Add(dc6);
ts.GridColumnStyles.add(dc7);
datagrid1.TableStyles.Add(ts);
procedure SetLookupBinding(combobx: System.Windows.Forms.Combobox;
DisplayColumn, BoundColumn: string; dt: DataTable);
begin
with combobx do
begin
DisplayMember := DisplayColumn;
ValueMember := BoundColumn;
DataSource := dt;
end;
end;
and the new class in a separate unit:
unit DataGridComboBoxColumnU;
interface
uses
System.Windows.Forms, System.Drawing, System.Data;
type
DataGridComboBoxColumn = class(System.Windows.Forms.DataGridTextBoxColumn)
private
{ Private-Deklarationen }
cm: CurrencyManager;
intCurrentRow: Integer;
cbb: Combobox; // Hosted combobox control
procedure comboBox_Leave(sender: System.Object; e: EventArgs );
procedure DataGrid_Scroll(sender: System.Object; e: EventArgs);
protected
procedure Edit(source: System.Windows.Forms.CurrencyManager;
rowNum: Integer; bounds: System.Drawing.Rectangle; readOnly: Boolean;
instantText: string; cellIsVisible: Boolean); override;
function GetColumnValueAtRow(source:
System.Windows.Forms.CurrencyManager;
rowNum: Integer): System.Object; override;
procedure SetColumnValueAtRow(source:
System.Windows.Forms.CurrencyManager;
rowNum: Integer; value: System.Object); override;
public
constructor Create;
function Combobx: Combobox;
end;
implementation
constructor DataGridComboBoxColu