Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

String grid and dropdown boxes

Posted on 2000-03-07
7
Medium Priority
?
335 Views
Last Modified: 2010-04-04
Hi,

Does anyone know how to put Dropdown boxes in the cells of a String grid such that you many select from the dropdown and have the result in the grid cell?

Is there a component out there that will do this?

Regards

0
Comment
Question by:ChrisBerry
7 Comments
 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2591741
I usually write this sort of thing myself...

Ensure the rowHeight is 21,

add an invisible comboBox to the StringGrid

Disallow the inplace editor for the cells you want

And when someone clicks that cell, show the combobox at that cellRect

(then you have to have the OnExit event of the comboBox write the data back -- this will require storing the edited column and row number with the ComboBox somehow -- I usually have a pointer to tPoint hanging off the Tag field)

Good luck, it _is_ possible...

Tim.
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2591847
I agree with AttarSoftWare,

It's possible to do.

Use combobox.OnKeyPress to prevent the user from changing the text (if thats what you want), like :
procedure THintForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
key:=chr(0);
end;

Use combobox.OnChange to detect when the user have selected an item from the list, like this :
procedure THintForm1.ComboBox1Change(Sender: TObject);
begin
.....:=ComboBox1.Text;
ComboBox1.Visible:=false;
end;

If you want to select the same string in the combobox you already have in the cell, you may consider to do somthing similar to this :
procedure ..........
begin
ComboBox1.Clear;
ComboBox1.visible:=true;
for i:=0 to xx do
 ComboBox1.Items.Add(Some-Values);
ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(The Value From Selected Cell);
end;

Regards
Peter
0
 
LVL 17

Expert Comment

by:inthe
ID: 2592332
Hi
The following example demonstrates popping up a Combobox
as an inplace editor to a Stringrid component ,i dont have much time to test it but you should be able to change to dbgrid:

procedure TForm1.FormCreate(Sender: TObject);
begin
 {The combobox height is not settable, so we will}
 {instead size the grid to fit the combobox!}
  StringGrid1.DefaultRowHeight := ComboBox1.Height; {Hide the combobox}
  ComboBox1.Visible := False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
 {Get the ComboBox selection and place in the grid}
  StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] :=
ComboBox1.Items[ComboBox1.ItemIndex];
  ComboBox1.Visible := False;
  StringGrid1.SetFocus;
end;

procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
 {Get the ComboBox selection and place in the grid}
  StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] :=
    ComboBox1.Items[ComboBox1.ItemIndex];
  ComboBox1.Visible := False;
  StringGrid1.SetFocus;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; Col,
 Row: Integer;  var CanSelect: Boolean);
var
  R: TRect;
begin  if ((Col = 3) AND
      (Row <> 0)) then begin
   {Size and position the combo box to fit the cell}
    R := StringGrid1.CellRect(Col, Row);
    R.Left := R.Left + StringGrid1.Left;
    R.Right := R.Right + StringGrid1.Left;
    R.Top := R.Top + StringGrid1.Top;
    R.Bottom := R.Bottom + StringGrid1.Top;
    ComboBox1.Left := R.Left + 1;
    ComboBox1.Top := R.Top + 1;
    ComboBox1.Width := (R.Right + 1) - R.Left;
    ComboBox1.Height := (R.Bottom + 1) - R.Top;   {Show the combobox}
    ComboBox1.Visible := True;
    ComboBox1.SetFocus;
  end;
   CanSelect := True;
end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 2593035
You could use TAdvStringGrid from http://www.tmssoftware.com/

Cheers,

Raymond.
0
 
LVL 2

Expert Comment

by:kubeerja
ID: 2593732
Check this tip it explains hoe you can do that.

http://members.truepath.com/delphi/tips/tip41_tstringgridtcombobox1.htm
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2594247
if you want to combine Combobox and DBgrid, infopower is good component.(but too expensive)
0
 

Author Comment

by:ChrisBerry
ID: 2636677
Ah! the joys of living in South Africa!

I am sorry it has taken so long to reply but my equipment was "affirmatively shopped" last week and I have had to replace a significant proportion of it so as to get back on line.

Thanks for all your replies, how to allocate the points?

On reflection, I think the answer that got me going the fastest gets the points - rwilson.

Cheers.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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