Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Add combo box inside grid 4

Status
Not open for further replies.

Bhashi

Programmer
Sep 13, 2022
15
LK
I have a grid as Grid1 and the columns are as below.
Code:
 Code    Qty        [b]  Delivery MODE[/b]
520B    100        
521B    300        
522B    500

I want to add a combo box to the Delivery MODE column to select one value from the Delivery MODE list. How can I do this? please assist me..
Thank you 
 
I assume you want to do this at design time? If so, follow these steps:

1. In the Form Designer, right-click on the grid, and choose Edit.

2. Click in the Delivery Mode column (the column itself, not the header). You should now see the name of that column in the drop-down list at the top of the Properties window.

3. Select a combo box from the form designer's toolbar, or the Project Manager window, or the Toolbox, or whatever. Drop it in the column.

4. Nothing seems to have happened. In fact, the combo box has been successfully added, but it is obscured by the existing textbox, which is still present. (You can confirm this by looking at the drop-down list at the top of the Properties window.)

5. So, the next step is to remove the textbox: Select the textbox in the drop-down list at the top of the Properties window. Be sure that it's the textbox in the column which also has the combo box.

6. Click on the title bar of the Form Designer (not on the form itself; if you do, you will de-select the combo box). Press the Del key.

You should now see the combo box in the column in the form designer.

When you run the grid, you will only see the combo in the row that has focus, which is probably what you want. But if you want to see the combo in every row at the same time, then set the columns Sparse property to .F.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I find it easier to add the control you want in the grid to the form itself first, as described by chpicker in thread184-230247
Otherwise Mike has described the necessity to choose sparse or not. But removing the textbox is optional, so steps 5 and 6 in Mikes description are not mandatory, you can do something else, you can set the column currentcontrol to the combobox.

There's another complication to solve, if you decide to only show the combo in the active row of the grid, the other rows will show their textbox. Indeed it won't matter if you remove the default text1 textbox of the column or keep it in, in sparse mode the rows besides the active row will show a textbox. And that will not necessarily be able to show the selection you made in the combobox. That will depend on the controlsource you set up in the combo. If that's the key of a record of a table of delivery modes, and the combo is set to display the column with the delivery mode as text, the other rows will show the key, though, not the text.

The next topic will be how to design the combobox so it's compatible for grid usage. As the grid has to have a recordsource and in that deliver mode column has to have a controlsource of the delivermode text or key. That controlsource also has to be the controlsource of the combobox, but you can't make the delivery mode text a controlsource to a list of delivery mode texts.

Now there are several ways out of this dilemma, but the simplest is to set the column to not be sparse and instead show the combobox in every row, also the non-active rows, which means the combo will display the selection made on each row, also when you leave the rows.

The combobox in every row isn't very esthetic design, but it's just a matter of taste.

All in all, let this just be a warning that overcoming the problem to just add the combobox into the grid, it's not the last hard problem about the construct of a grid also usable for entering data, even just in your still quite simple case of picking a mode.

Chriss
 
Just want to point out that the easiest way to add controls to grid columns is with the Toolbox. Just drag the class you want and drop it on the column.

Tamar
 
But, Tamar, don't you still have to put the grid in edit mode first? And don't you still have to either remove the existing text box or set the combo as the current control? If so, the steps I outlined would still be relevant.

I might well be wrong about this. I am quite ignorant of the Toolbox.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Nope, the Toolbox handles all that. It's really well-designed for this. It has an option that let you decide whether the control you drop replaces Text1 or is in addition.

The Toolbox is incredibly cool and after using it for a lot of years, I wouldn't want to have to add controls to forms any other way. Here's my paper on why people should use the Toolbox:
Tamar
 
The Toolbox is really awesome. Before it shipped, I didn't like any of the options for putting controls on forms. They all seemed clunky and annoying.

Tamar
 
Tamar, I didn't know that the toolbox is so feature rich. Thank you for sharing!



 
Thank you Tamar, I have never even looked at the toolbox before.
Text scraps looks useful.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top