Solved

Dropdown list in DBGrid or StringGrid?

Posted on 1998-09-14
6
1,766 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 107
Machine not responding during CopyFile() 3 98
Dynamically Created Query 3 55
DBGrid or StringGrid ? 6 88
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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