Jump to content


littlebigfred's Content

There have been 85 items by littlebigfred (Search limited from 30-March 23)


By content type

See this member's


Sort by                Order  

#12991 Using TNxCalcColumn and TNxGuidColumn?

Posted by littlebigfred on 22 October 2009 - 10:22 AM in NextGrid Component

I guess we shouldn't hold our breath for a User's Manual, because it's a lot of work to write this kind of thing, but as a so-so solution, is there a way to get the list of properties/methods for each column type, ie. the list that drops down when typing a "." after a column?

For instance, in...

CODE
TNxButtonColumn(Cell[ColumnByName['TNxButtonColumn'].Index,LastAddedRow]).


... I'd like to find a document that lists all the items that can be used after the dot (methods, properties, events).



#12990 Using TNxCalcColumn and TNxGuidColumn?

Posted by littlebigfred on 22 October 2009 - 03:17 AM in NextGrid Component

Thanks for the information.

Actually, what I think is missing, is some tutorial on the different types of columns supported by NextGrid, with a bit of examples for each.

I went through help.chm, dn.bergsoft.net and it seems the only small source of information are the demos, but it's always more time-consuming to figure out how a component works by having to go through source code :-/



#12989 Getting column type from dataset?

Posted by littlebigfred on 22 October 2009 - 01:54 AM in NextGrid Component

Hello

I have a couple of questions on how to go creating columns in a NextGrid from a dataset:

1. Is there a two-column list that maps NextGrid column types to compatible Delphi datatypes, eg. "TNxTextColumn = String", "TNxCheckBoxColumn = String, Boolean", "TNxNumberColumn = Integer, Double", etc.?

2. Is there a simple way to display the datatype returned by the dataset, and create a compatible column in a grid?

Here's the current code:
CODE
ASQLite3Query1.SQL.Text := 'SELECT * FROM mytable';
ASQLite3Query1.Open;

for mycol := 0 to ASQLite3Query1.FieldCount - 1 do begin
  //======== The quick way to see how wrapper maps SQLite to Delphi
  //E2250 There is no overloaded version of 'IntToStr' that can be called with these arguments
  //ShowMessage(IntToStr(ASQLite3Query1.Fields[mycol].DataType));

  //E2089 Invalid typecast
  //ShowMessage(String(ASQLite3Query1.Fields[mycol].DataType));

  //======== The longer way...
  case ASQLite3Query1.Fields[mycol].DataType of
    ftString:
      Columns.Add(TNxTextColumn,'My Col1');
    ftSmallint:
      Columns.Add(TNxNumberColumn,'My Col1');
    ftInteger:
      Columns.Add(TNxNumberColumn,'My Col1');
    ftWord:
      Columns.Add(TNxNumberColumn,'My Col1');
    etc.
  else
    ShowMessage('Other type');
  end;
end;


Thank you.



#12928 Hidding header to display rows as Slides?

Posted by littlebigfred on 14 October 2009 - 03:16 PM in NextGrid Component

Also, is there a way to display all the columns of a row at run-time, through code only?

For some reason, when I switch to Slide mode, only data from Col2 are displayed:

http://img79.imagesh...displayallz.jpg



#12927 Hidding header to display rows as Slides?

Posted by littlebigfred on 14 October 2009 - 02:29 PM in NextGrid Component

Hello

I'm learning about the Slide layout. When the user has double-clicked a row, I'd like to switch from Report mode to Slide mode and hide the header so that the grid only displays a list of rows as Slides.

I didn't find how to hide a grid's header. Can it be done?

Thank you.



#12924 goIndicator? lsHorizontalOnly?

Posted by littlebigfred on 13 October 2009 - 10:26 PM in NextGrid Component

Hello Boki

I don't display the indicator column, so that's why I wasn't seeing anything.

QUOTE
When GridLinesStyle = lsHorizontalOnly only horizontal grid lines are painted. This may give a nice effect.


I'm not seeing the lines when I do this. Do I need something else?

CODE
procedure TForm1.Button1Click(Sender: TObject);
begin
  With NextGrid1 do begin
    Columns.Add(TNxTextColumn,'My Col1');
    Columns.Last.Name := 'col1';

    Columns.Add(TNxTextColumn,'My Col2');
    Columns.Last.Name := 'col2';

    AddRow(1);
    CellsByName['col1',LastAddedRow] := 'test';

    AddRow(1);
    CellsByName['col2',LastAddedRow] := 'test2';

    //Lines not displayed
    GridLinesStyle := lsHorizontalOnly;
  end;
end;


Thank you.



#12923 Using TNxCalcColumn and TNxGuidColumn?

Posted by littlebigfred on 13 October 2009 - 10:19 PM in NextGrid Component

Hello

I'm going through the articles in the DevNet section, and would like to know how to use the TNxCalcColumn column and the TNxGuidColumn column.

CODE
NextGrid1.Columns.Add(TNxCalcColumn,'My Calc');

//E2003 Undeclared identifier: 'TNxGuidColumn'
NextGrid1.Columns.Add(TNxGuidColumn,'My GUID');


Would someone have a small sample handy?

Thank you.



#12922 Can NextGrid display sections like Inspector?

Posted by littlebigfred on 13 October 2009 - 08:40 PM in NextGrid Component

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);


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;


HTH,



#12917 goIndicator? lsHorizontalOnly?

Posted by littlebigfred on 13 October 2009 - 04:09 PM in NextGrid Component

Hello

I have a couple of questions:
  1. What does the goIndicator option do?
  2. Why don't horizontal lines appear in the grid when I set its GridLinesStyle property?


CODE
With NextGrid1 do begin
  Columns.Add(TNxTextColumn,'My Col1');
  Columns.Last.Name := 'col1';

  Columns.Add(TNxTextColumn,'My Col2');
  Columns.Last.Name := 'col2';

  AddRow(1);
  CellsByName['col1',LastAddedRow] := 'test';
  AddRow(1);
  CellsByName['col1',LastAddedRow] := 'test2';

  //What is it?
  Options := Options - [goIndicator];

  //Lines not displayed
  GridLinesStyle := lsHorizontalOnly;
end;


Thank you.



#12916 Why need to add "NxColumns, NxColumnClasses"?

Posted by littlebigfred on 13 October 2009 - 03:59 PM in NextGrid Component

Hello

I was wondering why it's necessary to always add those two units to the Use section, while other NextGrid units are appended automatically when adding a TNextGrid control to a form?

Thank you.



#12873 Enter edit mode and have whole cell selected?

Posted by littlebigfred on 07 October 2009 - 01:46 AM in NextGrid Component

Hello,

I'm used to using keyboard shortcuts, and I was wondering if it was possible for NextGrid to select the content of a cell automatically when the user enters edit mode, so as to avoid either deleting/writing or selecting/overwriting data:

http://img43.imagesh...ctwholecell.jpg

IOW, I click on a cell, hit F2 to enter edit mode, hit SHIFT-Home to select the content of the cell, then overwrite the content just by typing, and hit ENTER to validate and exit edit mode.

Can NextGrid save me the SHIFT-Home step, ie. select the whole text right after entering edit mode?

Thank you.



#12868 Different between ClearSelection and NoSelection?

Posted by littlebigfred on 06 October 2009 - 06:18 PM in NextGrid Component

Thanks for the clarification.



#12867 Find column from its header caption?

Posted by littlebigfred on 06 October 2009 - 06:17 PM in NextGrid Component

Thanks.



#12866 Setting whole row read-only?

Posted by littlebigfred on 06 October 2009 - 06:17 PM in NextGrid Component

Hello

I need to make some rows read-only. Currently, when the user double-clicks on a cell, I need to check its row index to allow/disallow editing.

To simplify the code, Is there a way to tell NextGrid that a whole row is read-only?

CODE
With NextGrid1 do begin
  //N.A.
  Row[LastAddedRow].ReadOnly := True;
end;


Thank you.



#12858 Different between ClearSelection and NoSelection?

Posted by littlebigfred on 06 October 2009 - 05:02 PM in NextGrid Component

Hello

Both seem to do the same thing, namely remove the focus from a selected cell. What is the difference between the two methods?

CODE
With NextGrid1 do begin
    if SelectedColumn = ColumnByName['value'].Index then begin
        //NoSelection;
        ClearSelection;
    end;
end;


Thank you.



#12856 Find column from its header caption?

Posted by littlebigfred on 06 October 2009 - 02:23 PM in NextGrid Component

Hello

I may have overlooked it, but I didn't find if it's possible to retrieve a column by its header caption? I'd like to do this in order to set the column's Name property without hard-coding the column index:

CODE
With NextGrid1 do begin
  //2nd param is caption, not name
  Columns.Add(TNxTextColumn,'Value');
  //GPF
  Columns.Column['Value'].Name := 'value';
end;


Thank you.



#12814 Ideas to edit joined SELECT?

Posted by littlebigfred on 24 September 2009 - 02:36 PM in NextGrid Component

For those interested, I came up with this solution: In case of a joined SELECT...
  1. include all the columns of all the tables involved
  2. make all columns read-only; if the user might need to edit some columns, make those editable
  3. hide the ID columns (eg. T1_id, T2_id), unless the user has a need for this information. Those are needed only to build the UPDATE query in the AfterEdit event
  4. for each column, use its Tag property: If set to nil, it's an "ID column" (ie. contains that part of the row's unique ID), if set to anything else, it's a "non-ID column" (ie. data linked to the parent ID) and the Tag contains the column index of its ID parent


For instance:
CODE
ColumnByName['T1_id'].Tag := nil;
ColumnByName['T1_label'].Tag := ColumnByName['T1_id'].index;
ColumnByName['T2_id'].Tag := nil;
ColumnByName['T2_somecolumn'].Tag := ColumnByName['T2_id'].index;


I'd rather that NextGrid provide a ParentIndex property instead of using the vague Tag property, but it does the job.

HTH,



#12809 Ideas to edit joined SELECT?

Posted by littlebigfred on 22 September 2009 - 08:07 PM in NextGrid Component

In case rows from a joined SELECT are displayed horizontally as usual, I haven't found a good solution to find a column's parent ID so that I can build the UPDATE query.

For instance:
1. Fill a grid with the following query: SELECT article_id, article_type_code, type_id, type_label FROM article,type WHERE article_type_code=type_id
2. In the grid, hide columns "article_id" and "type_id" since those are useless to the user, and are only needed to perform updates to the database
3. In the grid's AfterEdit event, find the table name and row ID the cell belongs to, and send query. For example, if the user has changed the content of the type_label column:

CODE
With NextGrid1 do begin
    query := Format('UPDATE how_to_find_table SET type_label="%s" WHERE how_to_find_row_ID=%s',[Cell[ACol,ARow],Cell[How_to_find_row_id]]);


Has someone come up with a good solution for this issue?

Thank you.



#12744 Tagging some rows for easy retrieval?

Posted by littlebigfred on 13 September 2009 - 04:39 PM in NextGrid Component

Thanks Boki.



#12741 Tagging some rows for easy retrieval?

Posted by littlebigfred on 12 September 2009 - 07:53 PM in NextGrid Component

QUOTE (Boki (Berg) @ Sep 12 2009, 12:42 AM) <{POST_SNAPBACK}>
Data property is a pointer type property. You may set it to nil if a row is "parent" and to parent row when row is "normal". You may also use a ObjectReference property of Cell too.


Thanks for the idea. Out of curiosity, what is the Level property for?

For those interested, here's some working code:

CODE
CellsByName['sql',0] := 'table1';
CellsByName['key',0] := 'Table 1';
CellsByName['value',0] := '(not editable)';
//If nil -> table row -> paint all cells green below
Row[0].Data := nil;

CellsByName['sql',1] := 'article.id';
CellsByName['key',1] := 'Article ID';
CellsByName['value',1] := '123';
//If not nil -> columns row -> leave color to white
Row[1].Data := GetParentComponent;

CellsByName['sql',2] := 'label';
CellsByName['key',2] := 'Label';
CellsByName['value',2] := 'My label';
Row[2].Data := GetParentComponent;

for myrow := 0 to RowCount - 1 do begin
  //Paint "table" rows green
  if not Assigned(Row[myrow].Data) then begin
    for mycol := 0 to Columns.Count - 1 do begin
      Cell[mycol,myrow].Color := clMoneyGreen;
    end;
  end;
end;


Thank you.



#12732 Tagging some rows for easy retrieval?

Posted by littlebigfred on 10 September 2009 - 03:41 PM in NextGrid Component

Hello

At this point, to tell if I need to paint a row differently because it's a table name, I loop through all the rows, check that the first (hidden) cell is painted green, and paint all the cells of the current row that way. I'd rather use something a bit smarter if possible.

A grid doesn't have the Tag property, so is there an alternative way to easily retrieve some rows by tagging them? I see the properties "Data" and "Level". What are they used for?

Here's what it looks like, and here's the code I use:

CODE
With NextGrid4 do begin
  CellsByName['sql',0] := 'table1';
  CellsByName['key',0] := 'Table 1';

  //"Table" row = 1, "column" row = 0
  //Row[0].Tag := 1
  //Row[0].Data
  //Row[0].Level
  Cell[ColumnByName['sql'].Index,0].Color := clMoneyGreen;

  CellsByName['sql',1] := 'article.id';
  CellsByName['key',1] := 'Article ID';
  CellsByName['value',1] := '123';

  for myrow := 0 to RowCount - 1 do begin
    //Poor man's way to check what type of row it is :-/
    if Cell[0,myrow].Color = clMoneyGreen then begin
      for mycol := 0 to Columns.Count - 1 do begin
        Cell[mycol,myrow].Color := clMoneyGreen;
      end;
    end;
  end;
end;


Thank you.



#12731 Can NextGrid display sections like Inspector?

Posted by littlebigfred on 10 September 2009 - 11:31 AM in NextGrid Component

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):

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;


HTH,



#12730 Can NextGrid display sections like Inspector?

Posted by littlebigfred on 10 September 2009 - 10:50 AM in NextGrid Component

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;



#12729 Can NextGrid display sections like Inspector?

Posted by littlebigfred on 10 September 2009 - 10:22 AM in NextGrid Component

Thanks for the tip smile.gif 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.



#12724 Can NextGrid display sections like Inspector?

Posted by littlebigfred on 09 September 2009 - 10:24 PM in NextGrid Component

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.