FAQ for TSMDBGrid component

Q1 How I can add the sorted column?
Q2 How I can clear the all sorted columns?
Q3 How I can change a standard TSMDBGrid glyphs (sorted arrows, indicator symbols etc)?
Q4 How I can change standard strings for messages?
Q5 How I can increase the width for Indicator column?
Q6 How I can display the images in Indicator column?
Q7 How I can display the multi-line captions for columns?
Q8 I want display the pictures in cells for graphic fields. How I can do it?
Q9 How I can assign the operations to standard menu items?
Q10 Can I use a standard popup menu and add the custom popup?
Q11 I want to disable the append and/or delete actions in grid
Q12 Can I fix some columns?
Q13 I want to display a hint for each cell.
Q14 How can I insert the checkbox in cells?
Q15 I want to display a dropdown and ellipsis buttons in cells.
Q16 My users want to use an Enter key like TAB for column navigation.
Q17 In standard DBGrid I have the event for data drawing only. Is there any event for title drawing?
Q18 I want to draw the rows with different colors.
Q19 I want change a color for odd rows.
Q20 How I can receive the latest news about TSMDBGrid, new builds and upgrades?

 

 

1. How I can add the sorted column?

You may do it in a few different ways:
- every column (TSMDBColumn type) have the SortType property

{add a new sorted column in list - ascending order}
(SMDBGrid.Columns[1] as TSMDBColumn).SortType := stAscending

{add a new sorted column in list - descending order}
(SMDBGrid.Columns[2] as TSMDBColumn).SortType := stDescending;

- as alternative, you may use the SetSortField method for TSMDBGrid

SMDBGrid.SetSortField(yourDataset.FindField('OrderNo'), stAscending);

go top

 

2. How I can clear the all sorted columns?

You may do it in a few different ways:

  • set the SortType property for every column (TSMDBColumn type) in stNone value
  • call the ClearSort method for TSMDBGrid
  • go top

 

3. How I can change a standard TSMDBGrid glyphs (sorted arrows, indicator symbols etc)?

You can run the Image Editor application (or any other resource workshop), open the SMDBGrid.RES file and change the any glyphs.

go top

 

4. How I can change standard strings for messages?

In SMCnst.PAS file you can find the any string resource and change it or translate on new language.

Now there are 20 languages (see RESOURCES sub-folder in original archive):

  Language   Language
 

English Dutch
French German
Spanish Spanish Mexican
Portuguese Brazilian Portuguese
Italian Greek
Japanese Danish
Slovenian Polish
Hungarian Turkish
Bulgarian Czech
Russian Ukrainian

If you'll translate the messages to the new language or will modify existing file, send the changed file to me (mshkolnik@scalabium.com) and I shall include it in the new build for public downloading.

go top

 

5. How I can increase the width for Indicator column?

For it's necessary to change value of WidthOfIndicator property.

Pay attantion to that width cann't be less than 11 (width of indicator in standard TDBGrid). Also if you include a eoCheckBoxSelect flag in ExOptions property for record selecting by checkbox, then minimum value is width of standard checkbox in a current Windows settings.

go top

 

6. How I can display the images in Indicator column?

Write the handler for OnGetGlyph event to provide customized drawing for the data in the Indicator column. You can define a glyph that will be displayed. And, of course, this event will be called for each row so you could define the different glyphs for records by your custom condition.

Note that the Indicator width will not be automatically increased, if the glyph could not be fit in the cell. You should set the width for Indicator column to fit the all information that will be displayed there (checkbox for record selection, row state glyph etc).

In the current version you can assign the bitmap only but in future I plan to add the any graphics (icons, metafile, jpeg etc)

go top

 

7. How I can display the multi-line captions for columns?

This feature is supported automatically - when you change a width of any column or add/remove the sorted type in column, width of columns will be recalculate automatically and if it's necessary title height will change!

go top

 

8. I want display the pictures in cells for graphic fields. How I can do it?

Just set a eoDrawGraphicField flag in ExOptions property.

go top

 

9. How I can assign the operations to standard menu items?

For each item in standard menu are created events:

  • OnAppendRecord event will be called with record append/insert in datasource
  • OnEditRecord event will be called with record editing in datasource
  • OnDeleteRecord event will be called with record deleting in datasource
  • OnPostData event will be called with post record in dataset
  • OnCancelData event will be called with cancel record in dataset
  • OnRefreshData event will be called with refresh item click
  • OnPrintData event will be called with print item click
  • OnExportData event will be called with export item click
  • OnSetupGrid event will be called with Setup of grid item click

All these events are very useful. For example, you can assign a procedure for append record, where you will create a new dialog with controls for every field. And always if your end-user will append the new record, your dialog will be shown.

Note that if you not assigned the code for some events then corresponded menu items will be hidden.

go top

 

10. Can I use a standard popup menu and add the custom popup?

Yes, of course.

When you included the eoStandardPopup flag in ExOptions property, the standard popup will be displayed by right button mouse click. But if you assigned the custom popup in Popup property then the standard popup will be displayed by click in "dropdown" cell only (top left cell: in title row of Indicator column).

go top

 

11. I want to disable the append and/or delete actions in grid

To include a eoDisableInsert and/or eoDisableDelete flag in ExOptions property.

go top

 

12. Can I fix some columns?

Yes, of course. See the FixedCols property. To customize the color for fixed columns you may in FixedColor property.

Also if you want to fix columns, but to save their original attributes, set the eoFixedLikeColumn flag in ExOptions property.

go top

 

13. I want to display a hint for each cell.

If you want to display a hint that contains the full string (truncated by cell width during view), include the eoCellHint flag in ExOptions property.
In this case during mouse move over any cell your end-user will see the hint window with full text for field value.

PS: if the field value fits in the cell completely (is not truncated), the hint window will be not displayed.

go top

 

14. How can I insert the checkbox in cells?

If you included the eoBooleanAsCheckBox flag in ExOptions property, then any boolean field will use the checkbox as standard editor in cell.

go top

 

15. I want to display the dropdown and ellipsis buttons in cells.

If you included the eoShowLookup flag in ExOptions property, then for each columns of every row (if specified the PickList property or ButtonStyle is cbsEllipsis or field is the Lookup-field) will be displayed the buttons (dropdown arrow or ellipsis). You can click on this button and action will be exeuted automatically (dropdown list displayed or assigned event executed)

PS: in the standard TDBGrid these buttons displayed only in editor mode.

go top

 

16. My users want to use an Enter key like TAB for column navigation.

Set the eoENTERlikeTAB flag in ExOptions property.

go top

 

17. In standard DBGrid I have the event for data drawing only. Is there any event for title drawing?

Yes, see an OnDrawColumnTitle event.

go top

 

18. I want to draw the rows with different colors.

If you want to draw the rows in TSMDBGrid with custom color/font etc, you can do it in a few different ways.

The first method is very-very simple:
you can write in OnGetCellParams event the procedure, where you'll check any own custom condition (value in field, for example) and change the font and/or background color.

Example 1:

procedure TForm1.SMDBGrid1GetCellParams(Sender: TObject; Field: TField;
  AFont: TFont; var Background: TColor; Highlight: Boolean);
begin
  {if CustNo less than 15, then set a bold font and red color in background}
  if Assigned(Field) and (UpperCase(Field.FieldName) = 'CUSTNO') then
  begin
    if Field.AsInteger < 15 then
    begin
      AFont.Style := [fsBold];
      Background := clRed;
    end
    else
    begin
      AFont.Style := [];
      Background := clWhite;
    end
  end
end;

The second method is:
you can write in OnDrawColumnCell event the procedure, where you'll check the condition and draw directly on grid canvas. In this case you can draw anything what you want - to draw shapes, images, to change the fonts and/or colors, to change a text position and more.

Example 2:

procedure TForm1.SMDBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  {if CustNo is 13 and is a second column,
   then draw image and text after it}
  if (Table1.FieldByName('CustNo').AsInteger = 13) and
     (DataCol = 2) then
  begin
    SMDBGrid1.Canvas.FillRect(Rect);
    SMDBGrid1.Canvas.Draw(Rect.Left, Rect.Top, Image1.Picture.Bitmap);
    SMDBGrid1.Canvas.TextOut(Rect.Left+20, Rect.Top+20, Column.Field.FieldName);
  end;
end;

go top

 

19. I want to change a color for odd rows.

You may use the GridStyle property and specitfy there any custom colors for Odd/Even rows or select any from predefined color schemes (price-list, MS Money etc)

Also as alternative, you may change the color as I described in previous topic - you can do it in OnGetCellParams or OnDrawColumnCell events. For example:

procedure TForm1.SMDBGrid1GetCellParams(Sender: TObject; Field: TField;
  AFont: TFont; var Background: TColor; Highlight: Boolean);
begin
  if (Table1.RecNo mod 2 = 1) then
    Background := clRed;
end;

PS: of course, RecNo is valid for local tables only (Paradox, DBase etc).

go top

 

20. How I can receive the latest news about TSMDBGrid, new builds and upgrades?

If you want to receive the latest news about TSMDBGrid development and new versions/announcements, then:

In this mailing list and newsgroups you can discuss the questions related to my components and/or applications (TSMDBGrid too, of course), receive the latest news about development, suggest the new features, send bug-reports, receive the updates, new versions and bug fixings.

Also there you can take the answer on any Delphi programming question.

If you want to contact me personally, send a message to mshkolnik@scalabium.com

go top


Download a lastest version: smcmpnt.zip

 

Borland Software Scalabium Software

Copyrightc 1998-2017, Scalabium Software. All rights reserved.
webmaster@scalabium.com

May 13, 2004