Hello
As a way to group data in a grid, I find this way of doing things in the Inspector interesting (Common Data, Sub Category, etc.)
Is there a way for NextGrid to do something similar? I don't necessarily need the treeview but I could use something like merging all the cells in a row so that it's clear that a series of rows belong to a group.
Thank you.
Can NextGrid display sections like Inspector?
Started by littlebigfred, Sep 09 2009 04:22 PM
7 replies to this topic
#1
Posted 09 September 2009 - 04:22 PM
#2
Posted 09 September 2009 - 05:48 PM
Cool, NextGrid can display data as a tree view:
http://img178.images...ekeydisplay.jpg
1. Is there a way to make sure child items are displayed correctly when the grid is shown?
The following code seems to only handle parent items, but doesn't go deeper and handle child items:
2. Is it possible to hide the "+/-" buttons for a treeview column built at run-time? The demo only shows this for a column created at design-time:
Thank you.
http://img178.images...ekeydisplay.jpg
1. Is there a way to make sure child items are displayed correctly when the grid is shown?
The following code seems to only handle parent items, but doesn't go deeper and handle child items:
CODE
for index := 0 to Columns.Count - 1 do begin
BestFitColumn(index, bfBoth);
end;
Columns.ResizeColumns();
BestFitColumn(index, bfBoth);
end;
Columns.ResizeColumns();
2. Is it possible to hide the "+/-" buttons for a treeview column built at run-time? The demo only shows this for a column created at design-time:
CODE
Columns.Add(TNxTreeColumn,'Key');
Columns[0].Name := 'key';
//NxTreeColumn1.ShowButtons := False;
Columns[0].Options := Columns[0].Options - [coShowButtons];
Columns[0].Name := 'key';
//NxTreeColumn1.ShowButtons := False;
Columns[0].Options := Columns[0].Options - [coShowButtons];
Thank you.
#3
Posted 09 September 2009 - 10:24 PM
An additional question :-)
In this example, I'd like to make the parent row (eg. "Table 1") read-only, and let the user edit any child row. Ideally, I'd like to just tell the grid that such and such row is read-only, instead of making the whole Value column read-only, and then check the value of the Key column every time the user double-clicks or hits F2 on a cell.
Thank you.
In this example, I'd like to make the parent row (eg. "Table 1") read-only, and let the user edit any child row. Ideally, I'd like to just tell the grid that such and such row is read-only, instead of making the whole Value column read-only, and then check the value of the Key column every time the user double-clicks or hits F2 on a cell.
Thank you.
#4
Posted 10 September 2009 - 04:49 AM
Hello Fred,
You may read GetParent method of NextGrid and then inside OnBeforeEdit set Accept parameter to False if row have no parent (GetParent = -1)
I hope that this helps
Best regards!
You may read GetParent method of NextGrid and then inside OnBeforeEdit set Accept parameter to False if row have no parent (GetParent = -1)
CODE
procedure TForm1.NextGrid1BeforeEdit(Sender: TObject; ACol, ARow: Integer;
var Accept: Boolean);
begin
if NextGrid1.GetParent(ARow) = -1 then
begin
Accept := False;
end;
end;
var Accept: Boolean);
begin
if NextGrid1.GetParent(ARow) = -1 then
begin
Accept := False;
end;
end;
I hope that this helps
Best regards!
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#5
Posted 10 September 2009 - 10:22 AM
Thanks for the tip At this point, the "Key" column is disabled and, thanks to the code above, in the "Value" column, only child rows can be edited.
I still have a couple of questions:
1. How can I make sure that the whole tree is visible when the grid is shown? Currently, calling "BestFitColumn(index, bfBoth)" + "Columns.ResizeColumns()" only takes care of parent rows, but not child rows:
http://img178.images...ekeydisplay.jpg
2. If I use "ColumnByName['value'].Editing := True", the grid switches to edit mode either by a single click or by starting typing. To avoid user errors, I'd like to switch to edit mode only when the user double-clicks or hits F2 on a cell.
Is the only way to do this is to catch both DblClick() and KeyDown() to switch to edit mode, and disable edit mode through AfterEdit(), or is there an easier way?
Thank you.
I still have a couple of questions:
1. How can I make sure that the whole tree is visible when the grid is shown? Currently, calling "BestFitColumn(index, bfBoth)" + "Columns.ResizeColumns()" only takes care of parent rows, but not child rows:
http://img178.images...ekeydisplay.jpg
2. If I use "ColumnByName['value'].Editing := True", the grid switches to edit mode either by a single click or by starting typing. To avoid user errors, I'd like to switch to edit mode only when the user double-clicks or hits F2 on a cell.
Is the only way to do this is to catch both DblClick() and KeyDown() to switch to edit mode, and disable edit mode through AfterEdit(), or is there an easier way?
Thank you.
#6
Posted 10 September 2009 - 10:50 AM
As for making sure that child rows are displayed instead of being cut off with a trailing "...", a solution I found is to just make sure that the Key column is 1/3 of the total grid:
CODE
Columns[0].Width := Width div 3;
#7
Posted 10 September 2009 - 11:31 AM
For those interested, here's some code to display a two-column Key/Value grid, where the Key column is a two-level TreeView so as to display table names + table columns of an SQL database, and in the Value column, only rows that belong to an SQL column are editable (table names can't be changed):
HTH,
CODE
//Called when user hits F2 or double-clicks on a cell
procedure TForm1.SwitchToEditMode;
begin
with NextGrid3 do begin
//Only column 'Value' can be edited
if SelectedColumn = ColumnByName['value'].Index then begin
//Parent rows in the Key column represent table names, so can't be edited
//Only child rows (items in the Value column) can be edited
if GetParent(SelectedRow) <> -1 then begin
Columns[SelectedColumn].Options := Columns[SelectedColumn].Options + [coEditing];
EditCell(SelectedColumn, SelectedRow);
end;
end;
end;
end;
procedure TForm1.NextGrid3DblClick(Sender: TObject);
begin
SwitchToEditMode;
end;
procedure TForm1.NextGrid3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = vk_F2) then begin
SwitchToEditMode;
end;
end;
//Disable editing again once user is through editing stuff in Value column
procedure TForm1.NextGrid3AfterEdit(Sender: TObject; ACol, ARow: Integer;
Value: WideString);
begin
with NextGrid3 do begin
Columns[SelectedColumn].Options := Columns[SelectedColumn].Options - [coEditing];
end;
end;
//Columns in grid are created at design-time
//because TNxTreeView.ExpandLock and TNxTreeView.ShowButtons can't be called at run-time
procedure TForm1.FormActivate(Sender: TObject);
var
index : Integer;
begin
with NextGrid3 do begin
ColumnByName['key'].Enabled := False;
ColumnByName['value'].Editing := False;
//Value column must use all available space on its right
Columns[Columns.Count - 1].Options := Columns[Columns.Count - 1].Options + [coAutoSize];
AddRow;
CellsByName['key',LastAddedRow] := 'Table 1';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key1';
CellsByName['value',LastAddedRow] := 'Value1';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key2';
CellsByName['value',LastAddedRow] := 'Value2';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key3';
CellsByName['value',LastAddedRow] := 'Value2';
//Couldn't find a better way to make sure child rows are fully displayed when grid is shown
{
for index := 0 to Columns.Count - 1 do begin
BestFitColumn(index, bfBoth;
end;
Columns.ResizeColumns();
}
//Have "Key" column be 1/3 of the total grid width
//so child rows are displayed OK
Columns[0].Width := Width div 3;
end;
end;
procedure TForm1.SwitchToEditMode;
begin
with NextGrid3 do begin
//Only column 'Value' can be edited
if SelectedColumn = ColumnByName['value'].Index then begin
//Parent rows in the Key column represent table names, so can't be edited
//Only child rows (items in the Value column) can be edited
if GetParent(SelectedRow) <> -1 then begin
Columns[SelectedColumn].Options := Columns[SelectedColumn].Options + [coEditing];
EditCell(SelectedColumn, SelectedRow);
end;
end;
end;
end;
procedure TForm1.NextGrid3DblClick(Sender: TObject);
begin
SwitchToEditMode;
end;
procedure TForm1.NextGrid3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = vk_F2) then begin
SwitchToEditMode;
end;
end;
//Disable editing again once user is through editing stuff in Value column
procedure TForm1.NextGrid3AfterEdit(Sender: TObject; ACol, ARow: Integer;
Value: WideString);
begin
with NextGrid3 do begin
Columns[SelectedColumn].Options := Columns[SelectedColumn].Options - [coEditing];
end;
end;
//Columns in grid are created at design-time
//because TNxTreeView.ExpandLock and TNxTreeView.ShowButtons can't be called at run-time
procedure TForm1.FormActivate(Sender: TObject);
var
index : Integer;
begin
with NextGrid3 do begin
ColumnByName['key'].Enabled := False;
ColumnByName['value'].Editing := False;
//Value column must use all available space on its right
Columns[Columns.Count - 1].Options := Columns[Columns.Count - 1].Options + [coAutoSize];
AddRow;
CellsByName['key',LastAddedRow] := 'Table 1';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key1';
CellsByName['value',LastAddedRow] := 'Value1';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key2';
CellsByName['value',LastAddedRow] := 'Value2';
AddChildRow(0);
CellsByName['key',LastAddedRow] := 'Key3';
CellsByName['value',LastAddedRow] := 'Value2';
//Couldn't find a better way to make sure child rows are fully displayed when grid is shown
{
for index := 0 to Columns.Count - 1 do begin
BestFitColumn(index, bfBoth;
end;
Columns.ResizeColumns();
}
//Have "Key" column be 1/3 of the total grid width
//so child rows are displayed OK
Columns[0].Width := Width div 3;
end;
end;
HTH,
#8
Posted 13 October 2009 - 08:40 PM
QUOTE
//Columns in grid are created at design-time
//because TNxTreeView.ExpandLock and TNxTreeView.ShowButtons can't be called at run-time
procedure TForm1.FormActivate(Sender: TObject);
//because TNxTreeView.ExpandLock and TNxTreeView.ShowButtons can't be called at run-time
procedure TForm1.FormActivate(Sender: TObject);
My mistake: I don't know enough about Delphi to know that a control can be typecast. In this particular case, a TreeColumn can be created at run-time and have its properties set thusly:
CODE
Columns.Add(TNxTreeColumn,'Key');
Columns.Last.Name := 'key';
//Those properties aren't available at design-time without typecasting
TNxTreeColumn(ColumnByName['key']).ExpandLock := False;
TNxTreeColumn(ColumnByName['key']).ShowButtons := False;
ColumnByName['key'].Enabled := False;
Columns.Last.Name := 'key';
//Those properties aren't available at design-time without typecasting
TNxTreeColumn(ColumnByName['key']).ExpandLock := False;
TNxTreeColumn(ColumnByName['key']).ShowButtons := False;
ColumnByName['key'].Enabled := False;
HTH,
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users