Jump to content
PiedSoftware

How do you set no row selected on TDrawGrid?

Recommended Posts

Hi

 

With TListBox and TComboBox, if you set ItemIndex to -1, nothing is selected. I tried setting DrawGrid.Row := -1 but that gives an error. Is there some other way to show nothing selected yet?

Share this post


Link to post
1 hour ago, PiedSoftware said:

With TListBox and TComboBox, if you set ItemIndex to -1, nothing is selected. I tried setting DrawGrid.Row := -1 but that gives an error. Is there some other way to show nothing selected yet?

You can't. What you can do is do the drawing yourself (isn't that necessary for TDrawGrid anyway?) and if nothing is supposed to be selected, don't draw the focus rectangle. But that would only be visual, If you read row and column they will still have some value. And it would also be necessary to somehow detect when something is being selected. It's easy to detect when the user clicks on something with the mouse, but more difficult when he wants to use the keyboard.

 

It might be easier to have a special row that contains the entry "<nothing>" or similar instead.

Share this post


Link to post
2 hours ago, dummzeuch said:

You can't. What you can do is do the drawing yourself (isn't that necessary for TDrawGrid anyway?)


There are some default things set, like font colour and background colour, and I am trying to stay as close to the defaults as I can,

Share this post


Link to post
Posted (edited)
Quote

Is there some other way to show nothing selected yet?

Set the Selection property to a TGridRect containing all -1's.

var
  gr: TGridRect;

gr.Left := -1;
gr.Right := -1;
gr.Top := -1;
gr.Bottom := -1;

DrawGrid.Selection := gr; 

 

Edited by Remy Lebeau

Share this post


Link to post
On 7/20/2021 at 5:46 PM, dummzeuch said:

You can't. What you can do is do the drawing yourself (isn't that necessary for TDrawGrid anyway?)


There are some default things set, like font colour and background colour, and I am trying to stay as close to the defaults as I can,

Share this post


Link to post
On 7/21/2021 at 2:00 AM, Remy Lebeau said:

Set the Selection property to a TGridRect containing all -1's.


var
  gr: TGridRect;

gr.Left := -1;
gr.Right := -1;
gr.Top := -1;
gr.Bottom := -1;

DrawGrid.Selection := gr; 

  


Thanks, that is the way I went and it had the desired effect on the appearance.

At first I tried to use a constant:

const
  EmptyRect: TGridRect = (Left: -1; Top: -1; Right: -1; Bottom: -1); // Copied from implementation of vcl.grids

procedure TGridDataRtti<T>.PopulateGrid(...);
begin
 ...
  grid.Selection := EmptyRect; 
 end;


But that gave me the spurious error message:
 E2506 Method of parameterized type declared in interface section must not use local symbol 'EmptyRect'

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×