Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep track of DBGrid clicks 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a form that displays a DBGrid with all the people who were scheduled to attend an orientation. What I'd like to do is have the user indicate which people were MISSING from the orientation, then I have to create a record (of hours attended for payment purposes) for all the people who did attend. Can someone suggest the best way to collect all the attendees or track the clicks of the absent people and exclude them? Or some other process to accomplish this that I'm clueless about? Thanks!

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
DBRadiobutton or DBCheckbox, although the checkbox named attended would be the most logical one. Steven van Els
SAvanEls@cq-link.sr
 
And can I put the checkbox in a column so that each person on the list has their own box? If that's correct, how do you put a check box in the DBGrid?

Thanks Steven, you rock!! Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
The DBCheckBox has the properties ValueChecked and ValueUncheked In your case I would use a column called Attended witht the values yes & no

The idea is to use a DBGrid and put an invisible dbcheckbox. Set the property of the DBgrid to alClient. If you do not wat to use the whole form, put the DBgrid on a panel.

Use the Field Editor to bring in the fields from the table or query


The DBCheckbox:

caption = attended
ValueCheked = yes
ValueUnchecked = no
Visible = false


You need to modify the following events:
OnDrawColumnCell to compute the place of the checkbox
OnColEnter to draw the checkbox
OnKeyPress for toggling the checkmark

The Code
Code:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if (gdFocused in State) and (Column.Field = table1Attended) then
   begin
     DBCheckBox1.SetBounds(
     Rect.Left + DBgrid1.Left+1,
     Rect.Top + DBGrid1.Top +1,
     Rect.Right - Rect.Left,
     Rect.Bottom - Rect.Top);
   end
end;

procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
  if DBGrid1.Columns [DBGrid1.SelectedIndex].Field =
  Table1Attended then
  DBCheckBox1.Visible := true
  else
  DBCheckbox1.Visible := False;
end;


procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if DBCheckBox1.Visible and (Ord(Key) > 31) then
  begin
    Key := #0;
    DBCheckBox1.Checked := not
      DBCheckBox1.Checked;
  end;
end;

Thanks to Marco Cantu (Mastering delphi 4 etc..)

Regards Steven van Els
SAvanEls@cq-link.sr
 
Thanks again Steven,

I actually borrowed a copy of his Mastering Delphi 6 book from a co-worker and found that bit of code. I've been side tracked to another project that is going to be implemented next week and needed some minor adjustments and haven't been able to get back to this yet. I'll post again if I have any problems.

la
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top