?
Solved

Multiselect in a TDBGrid

Posted on 1998-01-22
6
Medium Priority
?
1,213 Views
Last Modified: 2008-02-01
I am using D1 and WIN 3.11

I want to derive a component from TDBGrid so that the user can select more than one record.  I am almost there, but my problem is that the whole row gets highlighted, not just the cell(s) within the column that the user selects.

Here is a code snippet from my component:

If (FindRecordNumber >= FRangeStart) And (FindRecordNumber <= FRangeEnd) then
   If SelectedField = HighLightedField then
      If SelectedIndex = Col-1 then
      begin
           Colour := Canvas.Brush.Color;
           Canvas.Brush.Color := ClGreen;
           Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Field.AsString);
           Canvas.Brush.Color := Colour;
      end;

I probably got a bit carried away with my If statements, but I was trying to cover everything.
0
Comment
Question by:jdthedj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1357306
I don't fully get your problem. What do you want to select? A record (= row in a dbgrid) or a column?

Or do you just want to select the cell? Here is an example :
(Look at the header of the form. Think the way of getting the row and col selected is interesting) If I'm wrong, please specify the problem.

try it this way:

unit unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, DB, DBTables, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Table1: TTable;
    procedure DBGrid1ColEnter(Sender: TObject);
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
    procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
  private
    { Private declarations }

  public
    { Public declarations }
    procedure ShowRowCol;
  end;
  THack = class(TDBGrid);

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ShowRowCol;
begin
  caption := 'Row: ' + IntToStr(THack(DBGrid1).row) + '  ' + 'Col: ' + IntToStr(THack(DBGrid1).col);
end;

procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
  ShowRowCol;
end;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if (Sender as TDataSource).State = dsBrowse then ShowRowCol;

end;
Procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
   If gdFocused in State then
    with (Sender as TDBGrid).Canvas do begin
      Brush.Color := clRed;
      FillRect(Rect);
      TextOut(Rect.Left, Rect.Top, Field.AsString);
    end;
end;

end.



0
 
LVL 3

Author Comment

by:jdthedj
ID: 1357307
Hi ZifNab thanks for the reply.  I am wanting to select multiple cells in one column.  I have experimented further within my component (TDBGrid derivative) and I have managed to do what I want to do, but when I call Invalidate
the system locks up unless I click an adjacent column.  If I don't call Invalidate, the highlighting disappears as soon as I release the shift key.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357308
Mmmmm....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:jdthedj
ID: 1357309
Hi ZifNab - Mmmmmm indeed. After a lot of experimenting I have now decided that I will have to just highlight the first and last items of the requested block within the column
That at least works properly.  I still can't stop the Invalidating when I try to highlight all the required records.


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357310
jdthedj,
I soon have to make an adhanced dbgrid too. I'll try to make what you want too.
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1357311
Thanks ZifNab!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question