Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dropdown list in DBGrid or StringGrid?

Posted on 1998-09-14
6
Medium Priority
?
2,040 Views
Last Modified: 2008-03-17
Hi,

I have Delphi 4--how can I display a dropdown list in the grid when the user goes to edit the field.  What I need is for the user to be able to choose the data that goes in the field from a list of possible answers.  I believe that Delphi 3 and 4 are both able to do this but I don't have a clue how.  I don't want to use a DBComboBox but want similar functionality.

Thank you!
/MP
0
Comment
Question by:mikepj
[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
6 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1339702
How about this code???
------------
SG - StringGrid which is same as DBGrid
CB - ComboBox which is same as any other dropdown control

In OnDrawCell() of the StrGrid do this....

procedure TForm1.SGDrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
begin
     CB.Parent := SG;
     if (col = 1) and (row = 1)then
     with CB do begin
          Width := Rect.Right div 2;
          Height := Rect.Bottom;
          Top := Rect.Top;
          Left := Rect.Left;
     end;
end;
-----------
Try the code out and just need to replace the ComboBox with a control that can drop down....

Regards,
Viktor Ivanov
0
 
LVL 2

Author Comment

by:mikepj
ID: 1339703
Viktor,

Thank you for your reply.  It is very hard to make this work because of conflicts between the combo boxes and other problems that come up when you try to do strange things.  There must be a better way...

Thank you,
/MP

0
 
LVL 2

Author Comment

by:mikepj
ID: 1339704
Viktor,

Thank you for your reply.  It is very hard to make this work because of conflicts between the combo boxes and other problems that come up when you try to do strange things.  There must be a better way...

Thank you,
/MP

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1339705
I compiled it with Delphi and it worked fine . o O Is there any problem when you run it???

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:Marcius
ID: 1339706
There are some excellent components out there which give you much greater functionality when using grids. If you are using data bound stuff, then InfoPower is a must. They provide to option to next picklists into grid without any difficulty.

Orpheus from TurboPower is powerful, but quite difficult to get going with. They are non-data bound and have functionality similar to a string grid.

Hope this helps.
0
 

Accepted Solution

by:
Baruch earned 400 total points
ID: 1339707
You can add combo box to DBGrid with a easy way, to StringGrid it's more difficult, Here is how to to it with DBGrid in Delphi 2/3 I think it work with Delphi 4

1. select TTable and press right button a popup menu will popup
2. choice Fields Editor
3. a small windows will come up, press right button in the small window
4. choice Add fields (or Ctrl+A) and select the field for the table you need (you can select all the fields
5. If you fix values follow a section, if you want lookup values follow section b

  a. Select the DBGrid and press right button, choice columns
     editer from the popup menu, click on add all fields, high-
     light on column in the columns editor at the object
     inspector you will see
     {DBGrid Name}.Columns[{Index of column}]: TColumn, there is
     a property call PickList it a TString that you can enter
     values there (Delphi don't check if the value the use enter
     is in the PickList you need to do it by code}

  b. go to fields editor in TTable and press right button anc
     choice new field (Ctrl+N), a dialog window will popup,
     enter name for the lookupfield it type and size if it
     string check lookup in the radio button at field type
     at lookup definition choice the key field, dataset to look
     at key field to look at and the result field.
     now you have new field that bring values from dataset (only
     for there) and it will automate update the key field in  
     your table, you can choice not to show the key field in the
     DBGrid by delete it from the Columns Editor (the key field
     must be in the TTable Field list in fields editor)

I'll hope that will help you

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

688 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