Solved

String grid and dropdown boxes

Posted on 2000-03-07
7
313 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
Downloading email attachments 2 80
oracle global variables 4 76
Tembedded WB animatid gifs not animated on some pcs 2 84
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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