Solved

String grid and dropdown boxes

Posted on 2000-03-07
7
307 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now