Solved

String grid and dropdown boxes

Posted on 2000-03-07
7
324 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
[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
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
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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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 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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month5 days, 17 hours left to enroll

627 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