Solved

Dropdown list in DBGrid or StringGrid?

Posted on 1998-09-14
6
1,720 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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