Solved

String grid and dropdown boxes

Posted on 2000-03-07
7
305 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

22 Experts available now in Live!

Get 1:1 Help Now