Detecting column header click on FireMonkey TStringGrid [Edit]

I have a FireMonkey TStringGrid on a form that is bound to a TClientDataSet using LiveBinding. I'd like to order the grid by a specified column by allowing the user to click on the column header and then manually updating the dataset in code. However, I've yet to figure out how to detect a column click.

Does anybody know how to detect when a specific column header has been clicked on the TStringGrid? Does the TStringGrid automatically support this feature and I'm missing something?

Thank you.
-1
Joe
11/1/2011 7:27:52 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

2 Replies
2121 Views

Similar Articles

[PageSpeed] 55

> {quote:title=Joe Blow wrote:}{quote}
> I have a FireMonkey TStringGrid on a form that is bound to a TClientDataSet using LiveBinding. I'd like to order the grid by a specified column by allowing the user to click on the column header and then manually updating the dataset in code. However, I've yet to figure out how to detect a column click.
> 
> Does anybody know how to detect when a specific column header has been clicked on the TStringGrid? Does the TStringGrid automatically support this feature and I'm missing something?
> 
> Thank you.

I figured out a workaround. If anybody has a better way, please let me know.

When you click the column header of the TStringGrid, you're actually clicking on a TMenuItem. By default the TMenuItem's DragMode is dmAutomatic, so it doesn't register an OnClick, only an OnDblClick.

For my purposes, I don't want the users to change the column order, so I iterate through all the TMenuItems and set DragMode to dmManual and at the same time, assign the OnClick event in code.

Here's my code for iterating through the TStringGrid's TMenuItems:

{code}
var
  i: Integer;
  header: THeader;
  headeritem: THeaderItem;
begin
  // Hookup headeritem onclick
  header := THeader(StringGrid1.FindStyleResource('header'));
  for i := 0 to header.ChildrenCount - 1 do
  begin
    headeritem := THeaderItem(header.Children[i]);
    headeritem.DragMode := TDragMode.dmManual;
    headeritem.OnClick := MyColumnClick;
  end;
{code}

In the MyColumnClick, I can now determine the column number and the name:

{code}
var
  i: Integer;
  header: THeader;
  headeritem: THeaderItem;
begin
  header := THeader(StringGrid1.FindStyleResource('header'));
  for i := 0 to header.ChildrenCount - 1 do
  begin
    headeritem := THeaderItem(header.Children[i]);
    if headeritem = Sender then
    begin
      // Column number
      ShowMessage(IntToStr(i));
      // Header text
      ShowMessage(headeritem.Text);
      break;
    end;
  end;
end;
{code}

If I didn't need the column number, I wouldn't need the for..loop, I could just do THeaderItem(Sender) in the OnClick.
0
Joe
11/2/2011 12:47:15 PM
> {quote:title=Joe Blow wrote:}{quote}
> > {quote:title=Joe Blow wrote:}{quote}
> > I have a FireMonkey TStringGrid on a form that is bound to a TClientDataSet using LiveBinding. I'd like to order the grid by a specified column by allowing the user to click on the column header and then manually updating the dataset in code. However, I've yet to figure out how to detect a column click.
> > 
> > Does anybody know how to detect when a specific column header has been clicked on the TStringGrid? Does the TStringGrid automatically support this feature and I'm missing something?
> > 
> > Thank you.
> 
> I figured out a workaround. If anybody has a better way, please let me know.
> 
> When you click the column header of the TStringGrid, you're actually clicking on a TMenuItem. By default the TMenuItem's DragMode is dmAutomatic, so it doesn't register an OnClick, only an OnDblClick.
> 
> For my purposes, I don't want the users to change the column order, so I iterate through all the TMenuItems and set DragMode to dmManual and at the same time, assign the OnClick event in code.
> 
> Here's my code for iterating through the TStringGrid's TMenuItems:
> 
> {code}
> var
>   i: Integer;
>   header: THeader;
>   headeritem: THeaderItem;
> begin
>   // Hookup headeritem onclick
>   header := THeader(StringGrid1.FindStyleResource('header'));
>   for i := 0 to header.ChildrenCount - 1 do
>   begin
>     headeritem := THeaderItem(header.Children[i]);
>     headeritem.DragMode := TDragMode.dmManual;
>     headeritem.OnClick := MyColumnClick;
>   end;
> {code}
> 
> In the MyColumnClick, I can now determine the column number and the name:
> 
> {code}
> var
>   i: Integer;
>   header: THeader;
>   headeritem: THeaderItem;
> begin
>   header := THeader(StringGrid1.FindStyleResource('header'));
>   for i := 0 to header.ChildrenCount - 1 do
>   begin
>     headeritem := THeaderItem(header.Children[i]);
>     if headeritem = Sender then
>     begin
>       // Column number
>       ShowMessage(IntToStr(i));
>       // Header text
>       ShowMessage(headeritem.Text);
>       break;
>     end;
>   end;
> end;
> {code}
> 
> If I didn't need the column number, I wouldn't need the for..loop, I could just do THeaderItem(Sender) in the OnClick.


procedure TMainForm.StringGrid1HeaderClick(Column: TColumn);
begin

case Column.Index of
 1: ShowMessage('Column 1');
 2: ShowMessage('Column 2');
 3: ShowMessage('Column 3');
 4: ShowMessage('Column 4');

end;

end;

Edited by: Alexei Veclov on Jul 7, 2014 8:15 PM
0
Alexei
7/8/2014 3:15:58 AM
Reply:

Similar Artilces:

How move rows and columns in TStringGrid with Firemonkey
Hi everybody. I'm try move rows and columns in a StringGrid, but I not find the methods *Moverow* ou *MoveColumn* in *firmonkey* project. How to do this without this methods? > {quote:title=Spyder SC wrote:}{quote} > Hi everybody. > I'm try move rows and columns in a StringGrid, but I not find the methods *Moverow* ou *MoveColumn* in *firmonkey* project. > > How to do this without this methods? A grids columns are Children of the Grid. The order of columns is determined by their order in the Children array property. You should be able to insert or rearrange...

How I can get the column header name when i clicked on the concerned column header
Hi All I had a problem in getting the columnheader name . I had tried with dw.getcolumnname but not successfull . I was in very big dilema where to write the code(i mean what 'event') . Suppose i had a fullname as my columnheader then i should able to get the fullname when i click on that column. thanks vasu Vasu: You will want to code this in the clicked event. You can look at GetBandatPointer() and GetObjectatPointer() functions in help. HTH, Austin "vasu" <vasu@i-vantage.com> wrote in message news:UfS3lsO2CHA.345@forums.sybase.com... ...

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Firemonkey HowTo do a TStringgrid with inplace TCombobox [Edit]
Hi Forum, i'm new to XE2/Firemonkey - so this might be a beginners question. I'm trying to add a combo box to a stringrid. The stringgrid shows the content of a clientdataset. Somehow i'm not able to place the combobox at the right cell when clicked. Is there a similar way as it is used with the dbgrid in the VCL? Any help/hints? Regards Max Edited by: Max Schwarzbach on Mar 15, 2012 10:56 AM > {quote:title=Max Schwarzbach wrote:}{quote} > Hi Forum, > > i'm new to XE2/Firemonkey - so this might be a beginners question. > I'm trying t...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Firemonkey - XE 5 - Mac OS X Firemonkey HD App
My Firemonkey applications have no icon when they run in the dock. What is odd is that when I navigate in the finder to the app bundle to /Users/my_user_id/RADPAServer/scratch-dir I see the icon there, and if I open the app bundle, it contains the .icns file, which seems valid. But the Finder itself, in my iMac running OS X 10.8.5 seems to refuse to show the icon in the dock. Running the app bundle normally (not via RADPASERVER) also results in a broken icon. Note that if I make an icon myself, using the OS X app Icon Composer, and put it in there, it seems valid, but (a) the defau...

Delphi / FireMonkey release components created at runtime [Edit]
Hello, XE6, Win7 Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes. I declared this: im: TImage; as a TForm variable. Put this in .FormCreate: ReportMemoryLeaksOnShutdown := DebugHook <> 0; This picks up things like TStrokeBrush when I don't run .Free; I then put this in: procedure TFrmScales.Button4Click(Sender: TObject); begin im := TImage.Create(self); im.Bitmap.Assign(I_note.Bitmap); // I_note is a TImage that I put there at design-time im.Pa...

How do you rate you experience programming for IOS in Delphi/Firemonkey [Edit]
Hello: I've been taking a IOS programming course in objective-c/swift with xcode, and while doing my homework assignments I came to the conclusion that this is a very finicky environment, where very often things don't work as expected or there is always some minor UI glitch that has to be fixed or found workarounds for. Just to give you some examples (by far not an exaustive list): a UITableView doesn't align to the top when you use a navigation controller; upon selecting a row in a UITableView some buttons in the row disappear while the row is selected; specifying layout con...

Delphi 2010
Hi With new Delphi 2010 code i can't have a Dbgrid with ColumnClick event and column header Themed. i have see a new option in dbgrid : dgTitleClick :( if i active this property i lost themed blue rettangule when i move mouse over the column header ( it is like a very old dbgrid ) i'm using ThemedDBGrid unit , but don't work more in D2010 ( column header not Themed with OnTitleClick Assigned and dgTitleClick set to True ) How i can active ALL FEATURES of THEMED with OnTitleClick Assigned ? Edited by: Mauro Botta on Oct 13, 2009 11:54 AM upppp...

Does Delphi XE5 firemonkey work on current Samsung tablets? [Edit]
I am being told that Delphi XE5 with firemonkey will not work on the current range of Samsung tablets even if they have Android 4 is that true? If so I will be very disappointed having invested thousands of pounds and a few hundred hours to adopt the technology on the promise I can now deploy to Android mobile devices. When I run even the most simple Hello World app I simply get a black screen on my brand new Samsung tablet. I am told it only works on Android devices with a ARMv7 CPU supporting NEON instruction sets. If this is the case developers need to know that I have been told today by one of the major suppliers in the UK, Vodafone that it does not have any Android tablets in its range that is compatible with Delphi XE5. Can someone confirm this or if your using a new Samsung tablet please tell me if it works! Has anyone bought a 3g/4g tablet from Vodafone this year and deployed a Delphi firemonkey app to it? Edited by: Clive Morgan on Dec 4, 2013 7:21 PM if the tablet does not have the NEON CPU support then it wont work but it will work on samsung devives that do have that (e.g a samsung phone) it is a shame that it wont work on non NEON devices because it seems that even new device are not all having NEON CPU feature > {quote:title=Clive Morgan wrote:}{quote} > I am being told that Delphi XE5 with firemonkey will not work on the current range of Samsung tablets even if they have Android 4 is that true? > > If so I will be very...

How to stop firemonkey tStringGrid contol from highlighting entire row [Edit]
Any ideas on how to stop the default behaviour of a tStringGrid highlighting the entire row for all columns in the tStringGrid? I am just wanting to highlight the selected cell. Thanks Matthew Edited by: Matthew Shallvey on May 9, 2013 12:03 AM Edited by: Matthew Shallvey on May 9, 2013 12:07 AM > {quote:title=Matthew Shallvey wrote:}{quote} > Any ideas on how to stop the default behaviour of a tStringGrid highlighting the entire row for all columns in the tStringGrid? > I am just wanting to highlight the selected cell. > I suspect you'll need to modify the ...

How to show custom cursor on transparent firemonkey form Delphi XE3 [Edit]
HI. In my application I need to show a semi-transparent form with specific cursor. A simple example: procedure TForm1.FormCreate(Sender: TObject); begin Fill.Kind := TBrushKind.bkSolid; Fill.Color := $50000000; Top := 0; Left := 0; Width := 600; Height := 600; Transparency := true; Cursor := crSQLWait; end; but cursor is changed only when I start mouse moving. I don't know how to fix it:( Edited by: Sam Rob on Apr 8, 2013 1:31 AM decision: I add to onActivate: Cursor := crSQLWait; Application.ProcessMessages; ...

Delphi XE8 FireMonkey iOS Style problem with segmented buttons [Edit]
Hi, Going through some tutorials to get used to mobile development using FireMonkey and Delphi XE8. One of the most basic layouts tend to use the toolbar component with segmented speed buttons, and then applying the correct segmented style to each button. However, there seems to be an issue with the iOS style. [Screenshot.|https://drive.google.com/file/d/0B68Ju-patBf-RVVEMmI5UDd2cG8/view?usp=sharing] Using the "segmentedbuttonleft", "segmentedbuttonmiddle", and "segmentedbuttonright" styles is producing an extra border on the right button in iOS. It seems...

Firemonkey app from Delphi XE2 -> Dropbox & iCloud [Edit]
Im developing an app for iOS and MacOS Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2? > {quote:title=laureano bonilla wrote:}{quote} > Im developing an app for iOS and MacOS > > Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2 For iCloud, you will need support for both iOS 5.0 and 10.7 Lion. I don't believe XE2 even supports the classes added with iOS 4.x, much less 5.0, although you can parse the iOS 5.0 UIKit and Foundation headers yourself: http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parsing_...

Touch Gestures in Firemonkey 3D application Delphi XE3 MacOS [Edit]
Hi! I'm trying to create a MacOS Firemonkey 3D application with gestures enabled but I can't make it work. I can place a GestureManager on the form but there is no Touch property on the TForm3D object. Then I've tried to create a TLayer3D with a normal TPanel where I was able to set the Touch property but the gestures didn't work although it captured any other mouse movements. Then I've created a separate HD TForm with a GestureManager and with the Touch property set which worked as a stand alone form but whe n I've linked a touch enabled TPanel on the HD TForm to t...

MIDA - VCL To FireMonkey
More than 1200 people follow the Mida page on FaceBook ! These numbers lead us to be one of the most followed page for Delphi on FaceBook, to reward all of our readers, the first questionnaire of Mida. Answer the question faster. among all will extract a winner, *prize n.1 Mida licence with lifetime updates !!* What function you'd like to see in future versions of Mida ? http://www.facebook.com/Mida.FireMonkey ...

Firemonkey
I am so dammed frustrated with firemonkey and livebindings. The VCL + DB Controls were fast, consistent, and stable. This fmx framework is crap. It's slow on my i5 Macbook. I'd be embarrassed to put out an app like this. The help is lousy and apparently very few people are using it based on my failed Google searches. I can see why. Livebindings is cute when you have a few fields, but it a rats nest when you have a moderately complex form and have to wire up dozens of controls. There is no official support for nullable fields in livebindings which blows my mind....

New video of camera surveillance app made with Delphi XE5 and FireMonkey [Edit]
Hello guys I know that most of you have already seen the video from our mobile camera surveillance system, but today I uploaded a new video showing the final version, which has a much better interface than the previous version, along with some nice features that you all will like to see. I would recommend the PTZ and Virtual Matrix sections which shows some nice GUI controls made with Firemonkey http://www.youtube.com/watch?v=4lQGA8-sO9w The app is also available for download for Android, instructions are available on the video description > {quote:title=Eric Fleming Bonilha wrote:}{quote} > Hello guys > > I know that most of you have already seen the video from our mobile camera surveillance system, but today I uploaded a new video showing the final version, which has a much better interface than the previous version, along with some nice features that you all will like to see. > > I would recommend the PTZ and Virtual Matrix sections which shows some nice GUI controls made with Firemonkey > > http://www.youtube.com/watch?v=4lQGA8-sO9w > > The app is also available for download for Android, instructions are available on the video description That's very impressive. When I get home I'll play around with the app, but just seeing the video was great. It's encouraging to know Firemonkey can do this sort of thing! Eric Fleming Bonilha wrote: > Hello guys > > I know that most of you have alrea...

Delphi XE5(U2) Firemonkey application crashes at startup on OSX on new mac [Edit]
Hello, I'm trying to deploy my first application on a mac platform. I have successfully built the application on my dev mac and run it through PAServer and now I would like to deploy it on a different MacOS. I tried to drag and drop the application .app file into the application folder of the new Mac. The app shows up but as soon as I start it, I got a message telling me that it stopped unexpectedly. I'm really lost here: With windows, I'd have no problem finding out what is wrong but, with a Mac, I haven't got a clue what I did wrong. The application doesn't do an...

ANN: FireDataGrid 1.0 beta 3 for Delphi XE6 (Firemonkey) has been released! [Edit]
Dear colleagues, we are pleased to announce that version FireDataGrid 1.0 beta 3 for Delphi XE6 (Firemonkey) has been released. Version is quite stable and can be considered as a release candidate. This demo version adds two examples. MultiSelectDemo - demonstrates the ability to work in several selection modes (single row, multiple rows, single cell many cells, selection with rubber band and etc.). CustomEditorDemo - demonstrates the ability to embed custom cell editor to the grid view. In the example are being reviewed two options of the editors, based on embedded TControl and direct int...

Getting the column number when clicking on a column header
How can I get the column number when I click on a column header in a grid/tabular datawindow? I need the column number because I want to sort the column Ascending/Descending when clicking on the header. (I cannot presume that the column header has the name xxx_t!) -- Tone Hansen ADB systermer ASA e-mail: th@adbsys.no Tone Hansen wrote in message <01bcda30$3f804eb0$a75d13c2@ws_pro_th>... >How can I get the column number when I click on a column header in a >grid/tabular datawindow? > >I need the column number because I want to sort the column >Ascending/...

Right clicking on column in SQL Central (Edit column properties)
Hello, I am using SQL Central and am trying to edit a columns properties. The SQL Central Help instructs me to select a column and then either right click on the selected object or clicking Properties in the File menu. Double clicking is another option. The problem is that I cannot select anything in the right panel (has Name ,Type ,Default Value and Comments across the top). The items displayed are Add Column and 2 of my columns with an open book icon. I can Select All and invert the selection but I can't select a single item. Nor can I right click on any item. I can't ev...

Printing with FireMonkey [Edit]
Hello, I'm playing around with FM using FMX.Printer and I'm trying to figure out how to change the printer orientation programmatically. I've tried {code}Printer.Orientation := TPrinter.Orientation.poLandscape;{code} but unsuccessfully, as it triggers an error, saying that this line of code cannot be used here. Am I missing something? Edited by: Pasquale Esposito on Feb 19, 2014 4:38 AM > {quote:title=Pasquale Esposito wrote:}{quote} > Hello, > > I'm playing around with FM using FMX.Printer and I'm trying to figure out how to change the p...

Installing components for FireMonkey HD and FireMonkey iOS
Hi, How do I install components for both FireMonkey HD and FireMonkey iOS? I have one package 'FMXMyFireMonkeyControl' and 'FMIFireMonkeyControl' which both point to the same file with the same registration 'TFireMonkeyControl'. If I compile one package (FMXMyFireMonkeyControl) it installs correctly, then change the include file (FMCompile.INC) to compile for IOS (FMIFireMonkeyControl) which is included in the FMX.FireMonkeyControl.pas file: {$I FMCOMPILE.INC} uses {$IFDEF COMPILEIOS} FMX_Types, FMX_Objects, FMX_Forms, FMX_Dialogs, FMX_Effe...

Web resources about - Detecting column header click on FireMonkey TStringGrid [Edit] - embarcadero.delphi.firemonkey

SwissDelphiCenter.ch : English
All about Borland Delphi. Programming tips, downloads, forums, news, topsites, newsletter

FireMonkey Q&A
Questions and answers from a FireMonkey webinar

Borland's Dead C Scrolls
Historic computer documents are often lost in the mists of time. But not always - and it's with great pleasure that we can offer you a manuscript ...

Resources last updated: 3/8/2016 2:07:39 AM