Solved

Dropdown list in DBGrid or StringGrid?

Posted on 1998-09-14
6
1,690 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
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
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 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 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

19 Experts available now in Live!

Get 1:1 Help Now