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

x
?
Solved

DBGrid Picklist

Posted on 1999-07-01
20
Medium Priority
?
3,301 Views
Last Modified: 2016-10-08
Is there a way to prevent a user from typing in a value directly and forcing him to select an option from the picklist?

I want the same functionality for my DBGrid.Columns[i] as I can get in a ComboBox by setting the Style to csDropDownList.

Thanks.
0
Comment
Question by:WaltKay
[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
  • 10
  • 5
  • 3
  • +2
20 Comments
 

Author Comment

by:WaltKay
ID: 1385624
Perhaps I wasn't clear... I want to prevent a user from typing in a value directly INTO A DBGRID CELL and force him to select an option from the picklist?

I know how to get the picklist set up, but can't prevent putting in an entry that doesn't match the list.  I imagine I could write an involved OnKeyDown event to check against the picklist, but I am hoping there is an easier way.

Thanks in advance.


0
 
LVL 15

Expert Comment

by:simonet
ID: 1385625
Delphi already has this functionality built-in. All you have to do is to create a lookup field.

Alex
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385626
>>>mark<<<
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:WaltKay
ID: 1385627
Simonet, I tried to set up a LookupDataSet, LookupKeyField, KeyField, and LookupResultField for the specific field of the query I am interestd in... This approach didn't work well with the DBGrid1.Columns[0].Picklist elements.  

For 75 points ... Here's a bit more detail.

1) Here's how I set up my picklist:
   // Set up Code PickList Based on TableCode
   DBGrid1.Columns[0].Picklist.Clear;
   TableCode.First;
   While not TableCode.Eof do
   begin
      sDummy := TableCode.FieldByName('Code').AsString +
      ':  ' + TableCode.FieldByName('Descr').AsString;
      DBGrid1.Columns[0].Picklist.Add(sDummy);
      TableCode.Next;
   end;

2) The resulting DBGrid picklist looks something like:
   L1: Manager
   L2: Engineer
   L3: Designer

3) Since my CODE field in the Grid is only two
   characters long, it only picks up the first
   two characters (L1, L2, L3) ... Brilliant!

4) I like being able to see a picklist that has
   the code and a description... But need to keep
   people from typing in invalid
   codes (X1, P4, etc.)

Perhaps I'm just doing the lookup field incorrectly?

Any clarifications would be helpful.
0
 

Author Comment

by:WaltKay
ID: 1385628
Oops, I said "For 75 points..."
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385629
hi all,

alex's suggestion will work,
but needs a lookup-table (your picklist as a table)

a other solution could be to define a CustomConstraint like

YourPhysicalFieldName = YourPickListEntry1 or
YourPhysicalFieldName = YourPickListEntry2 or
YourPhysicalFieldName = YourPickListEntry3 or
YourPhysicalFieldName = YourPickListEntry4  . . . and so on

you can additional define a constraintErrorMessage like

This Entry is not available for this Field. Please Select from the List.

you can get this properties by doubleclicking of the table-component,
then rightclick on the appeared window, select add fields, ok
select your field now, adjust the propertys in the object-inspector

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385630
hey, just not seen your last comment?
but this should be easy do built up a lookupbox.

well, alex can do this, his suggestion ;-)

meikl
0
 

Author Comment

by:WaltKay
ID: 1385631
How would the lookup field work?

I tried:
TableCode.LookupDataset := TableCode;
TableCode.KeyFields := 'Code';
TableCode.KeyLookupFields := 'Code';
TableCode.KeyResultField := 'Code';

This didn't seem to have any effect on my DBGrid at all...  

When I cleared the DBGrid.Columns[0].Picklist, I expected to get a new picklist in the DBGrid based on the Lookup Field.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385632
hi WaltKay,
be sure that the fieldkind is fkLookup and not fkData.
meikl
0
 

Author Comment

by:WaltKay
ID: 1385633
I set FieldKind to FkLookup and the field in the DBGrid now shows up blank.  

Should I expect to see a pulldown menu in the DBGrid for this field?  I checked to confirm that the column on the DBGrid has a Button Style of "Auto".

I'm pretty convinced that I can't do what I want with lookup fields!  Can it let me select from a field called DESCR and populate my database with the corresponding CODE?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385634
ok, lets go,

-double-click your master-table-component
-rightclick on the column-editor
-select add new field
-in the poped up dialog give a name
-in typ select the datatyp, in your case string
-in FieldTyp select lookup
-in the lookup definition
--keyfield,select in your case Code
--dataset,select your lookuptable or -query
--Lookupkey, select in your case Code
--LookupResultField, select in your case descr
-OK

in your grid you can now hide your code-field
and your new added field is appeared

the user selects now the descr and cant write anything in it.
stored in your table will the code correspondending on the selection

good luck on the try
i've tested it, and it works fine
if you have any problems, just comment

meikl
0
 

Author Comment

by:WaltKay
ID: 1385635
Increased to 100 points - to kretzschmar for his diligence if no one can completely accomplish what I am trying to do.

Kretzschmar, I understand what you have done and it is quite close to what I'm after... However, I don't want to show the description on the DBGrid at all.  That takes up too much space.  I want to use the description in the picklist ONLY, then the DBGrid should only show the code.  That's the functionality I really want.  I repeat items 2 and 3 from my original request:

2) The resulting DBGrid picklist looks something like:
   L1: Manager
   L2: Engineer
   L3: Designer

3) Since my CODE field in the Grid is only two
   characters long, it only picks up the first
   two characters (L1, L2, L3) ... Brilliant!

The method you outlined certainly works, but in order for me to read the pulldown of the description, I have to make my grid column VERY wide (My actual codes and descriptions are longer than I put in my question).  If I use the picklist approach rather than the lookup approach, the pulldown automatically expands to fit the longest string.... If you could help me get the lookup pulldown to stretch, that would give me a 95% perfect solution - I could keep the column width narrow to only show the code (even though the description would be there, too).  Then, when I select the pulldown, it would be wider than the column and show the full description for the user to select from.

Thanks,
Walt

0
 

Author Comment

by:WaltKay
ID: 1385636
Make that 150 points...
0
 
LVL 15

Expert Comment

by:simonet
ID: 1385637
WaltKay,

please read the following article:

http://www.undu.com/Articles/990504b.html

I am sure it will shed some light on your problem.

yours,

Alex
0
 

Author Comment

by:WaltKay
ID: 1385638
Thanks, Alex

Please post an answer so I can credit you with points.

-Walt
0
 
LVL 15

Accepted Solution

by:
simonet earned 450 total points
ID: 1385639
Thank you, WaltKay. I am glad you got it working.

Here's my comment, now as an answer:

please read the following article:

http://www.undu.com/Articles/990504b.html 

I am sure it will shed some light on your problem.

Take care.

Alex

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1385640
yup, thats it ;-)
0
 

Author Comment

by:WaltKay
ID: 1385641
I can't argue that Alex has has answered the question as accurately as possible since I asked for "... the same functionality for my DBGrid.Columns[i] as I can get in a ComboBox."  That's what the article is all about!

Meikl, I'll post another question for you with my remaining points (only 55, sorry) for your hard work.  I appreciate your time.

Thanks to both of you, I've learned a lot and my app is coming along!

Thanks,
Walt
0
 

Author Comment

by:WaltKay
ID: 1385642
I can't argue that Alex has has answered the question as accurately as possible since I asked for "... the same functionality for my DBGrid.Columns[i] as I can get in a ComboBox."  That's what the article is all about!

Meikl, I'll post another question for you with my remaining points (only 55, sorry) for your hard work.  I appreciate your time.

Thanks to both of you, I've learned a lot and my app is coming along!

Thanks,
Walt
0
 

Expert Comment

by:Gautier Bakala
ID: 41835567
Hi.
sDummy is undeclared. how to declare it.

Thanks.
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

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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

704 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