Before I go ahead and write some code... I was wondering how you guys manage editing data that were SELECTed from multiple tables, ie. joined, and displayed in a grid:
CODE
SELECT article.id, type.label FROM article,type WHERE article.type_id = type.id
In case we need to let the user edit any column from any of the tables that ended up in the SELECT, I was thinking of displaying all the columns in a vertical grid as "key=value", and display each section in a different color to make it obvious that we are editing data that live in different tables (here's a screenshot):
CODE
With NextGrid1 do begin
//Create three columns, with first column hidden
Columns.Add(TNxTextColumn,'SQL');
Columns[0].Name := 'sql';
Columns[0].Visible := False;
Columns[0].Options := Columns[0].Options - [coCanSort];
Columns[0].Options := Columns[0].Options + [coFixedSize];
Columns.Add(TNxTextColumn,'Key');
Columns[1].Name := 'key';
Columns[1].Enabled := False;
Columns[1].Color := clBtnFace;
Columns[1].Options := Columns[1].Options - [coCanSort];
Columns[1].Options := Columns[1].Options + [coFixedSize];
Columns.Add(TNxTextColumn,'Value');
Columns[2].Name := 'value';
Columns[2].Options := Columns[2].Options - [coCanSort];
Columns[2].Options := Columns[2].Options + [coFixedSize];
FixedCols := 1;
Columns[Columns.Count - 1].Options := Columns[Columns.Count - 1].Options + [coAutoSize];
//Add rows, with the first group of rows = table1, and second group = table2
AddRow(10);
//SELECT article.id, type.label FROM article,type WHERE article.type_id = type.id
CellsByName['sql',0] := 'article.id';
CellsByName['key',0] := 'Article ID';
CellsByName['value',0] := '123';
//How to set color of cell using the column name?
Cell[2,0].Color := clMoneyGreen;
CellsByName['sql',1] := 'article.price';
CellsByName['key',1] := 'Price';
CellsByName['value',1] := '12';
Cell[2,1].Color := clMoneyGreen;
//Background color back to normal
CellsByName['sql',2] := 'type.id';
CellsByName['key',2] := 'Type ID';
CellsByName['value',2] := '456';
CellsByName['sql',3] := 'type.label';
CellsByName['key',3] := 'Label';
CellsByName['value',3] := 'Coat';
for index := 0 to Columns.Count - 1 do begin
BestFitColumn(index, bfBoth);
end;
Columns.ResizeColumns();
end;
//Create three columns, with first column hidden
Columns.Add(TNxTextColumn,'SQL');
Columns[0].Name := 'sql';
Columns[0].Visible := False;
Columns[0].Options := Columns[0].Options - [coCanSort];
Columns[0].Options := Columns[0].Options + [coFixedSize];
Columns.Add(TNxTextColumn,'Key');
Columns[1].Name := 'key';
Columns[1].Enabled := False;
Columns[1].Color := clBtnFace;
Columns[1].Options := Columns[1].Options - [coCanSort];
Columns[1].Options := Columns[1].Options + [coFixedSize];
Columns.Add(TNxTextColumn,'Value');
Columns[2].Name := 'value';
Columns[2].Options := Columns[2].Options - [coCanSort];
Columns[2].Options := Columns[2].Options + [coFixedSize];
FixedCols := 1;
Columns[Columns.Count - 1].Options := Columns[Columns.Count - 1].Options + [coAutoSize];
//Add rows, with the first group of rows = table1, and second group = table2
AddRow(10);
//SELECT article.id, type.label FROM article,type WHERE article.type_id = type.id
CellsByName['sql',0] := 'article.id';
CellsByName['key',0] := 'Article ID';
CellsByName['value',0] := '123';
//How to set color of cell using the column name?
Cell[2,0].Color := clMoneyGreen;
CellsByName['sql',1] := 'article.price';
CellsByName['key',1] := 'Price';
CellsByName['value',1] := '12';
Cell[2,1].Color := clMoneyGreen;
//Background color back to normal
CellsByName['sql',2] := 'type.id';
CellsByName['key',2] := 'Type ID';
CellsByName['value',2] := '456';
CellsByName['sql',3] := 'type.label';
CellsByName['key',3] := 'Label';
CellsByName['value',3] := 'Coat';
for index := 0 to Columns.Count - 1 do begin
BestFitColumn(index, bfBoth);
end;
Columns.ResizeColumns();
end;
What would be the best way to pull this trick? Is there an easy way to select a group of rows and change their background color in one go?
Thank you.