Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: DBGrid Question


This question is answered.


Permlink Replies: 2 - Last Post: Feb 23, 2018 10:27 AM Last Post By: Earl Staley Threads: [ Previous | Next ]
Earl Staley

Posts: 99
Registered: 4/9/07
DBGrid Question  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2018 3:19 PM
I would like to sort the records in a DBGrid by the FieldName when the user clicks the DBGrid->Columns->Items[?]->Title->Caption at the top of the DBGrid. I want the DBGrid sort to work similar to the way Windows File Explorer sorts the files when the column header is clicked.

How can I detect when a particular column header is clicked on a DBGrid?

Earl Staley
Greg Reese

Posts: 100
Registered: 7/15/05
Re: DBGrid Question
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2018 10:23 AM   in response to: Earl Staley in response to: Earl Staley
Earl Staley wrote:
How can I detect when a particular column header is clicked on a DBGrid?

Earl Staley
Write an OnTitleClick event handler and if the column is the one you want to sort, do so. For example,

void __fastcall TForm4::DBGrid1TitleClick(TColumn *Column)
{
        // if column title is that of column you want to sort, do the sorting
	if( Column->Title->Caption == L"columnToSort" )
	{
		// do sorting
		// ...
        }
}


Greg Reese
Earl Staley

Posts: 99
Registered: 4/9/07
Re: DBGrid Question  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2018 10:27 AM   in response to: Greg Reese in response to: Greg Reese
Greg,

I'm feeling a little stupid now. I didn't even know there was an OnTitleClick event.

My bad...
Earl Staley
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02