Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dropdown list in DBGrid or StringGrid?

Posted on 1998-09-14
6
Medium Priority
?
2,108 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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