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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox and Check Box in a Grid

Status
Not open for further replies.

Saif_Abc

IS-IT--Management
Apr 7, 2021
27
0
0
AE
Hi,

Is it possible to use either check box or Textbox in a grid depends upon the requirement??

Please check this image.

If the Remaining is zero then no need of check box and vice versa.

Please suggest.

Thanks

Saif
grid1_fgceyi.png
 
Yes, this is quite possible, and not unusual.

What you need to do is to place both a text box and a checkbox into the relevant column. Then you use the Column's DynamicCurrentControl property to choose between them.

There is alreay a textbox in the column, so you only need to add the checkbox. Assuming its Name property is set to Check1, you need the following code in the grid's Init:

Code:
this.Column8.DynamicCurrentControl = ;
  "IIF(Remaining = 0, "Check1", "Text1")"

(Change the column number as appropriate.)

You might also need to set the column's Sparse property to .F.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
And if you are not sure how to go about adding the checkbox:

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

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

3. Select a checkbox in the toolbar, Project Manager window, Toolbox, or whatever. Drop it in the column.

Don't worry if you can't immediately see the checkbox. It is there, but it might be hidden by the textbox (which was there all the time). You can confirm this by looking at the drop-down list at the top of the Properties window.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for the reply!

It works as seen in image, but ..
I want to remove "F" which is a logical field in column. Is it possible???

Thanks

Saif
grid2_h7jk9b.png
 
The poblem here is that the underlying fields (that is, the ControlSource fields for the W/H and Factory columns) are logical data types. That's what you want, because the columns also contain checkboxes. But in the rows where Remaining is not zero, it is the textbox which is visible. A logical field appears in a textbox as T or F.

An easy solution is to set the column's InputMask property to Y. Will that solve the problem, or do you want to display something esle in place of T or F?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you want the columns where Remaining <> 0 to be blank, you could try adding a Label control to the columns (in the same way that you added the checkbox). Then change the code from this:

Code:
this.Column8.DynamicCurrentControl = ;
  'IIF(Remaining = 0, "Check1", "Text1")'

to this:

Code:
this.Column8.DynamicCurrentControl = ;
  'IIF(Remaining = 0, "Check1", "[highlight #FCE94F]Label1[/highlight]")'


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for the reply!

set the column's InputMask property to Y. Will that solve the problem, or do you want to display something esle in place of T or F?

What is the other solution? I want blank column instead of any thing.

Thanks

Saif
 
I think you can override the column.controlsource with each conrols (text1, check1) individual controlsource.

So the ccheckbox can remain at alias.boolfield, but you could set the text1 controlsource to [(iif(boolfield,'',''))], which makes it readonly and empty.
 
Thanks Mike, it is done!!

Please check this.

Thanks Chris too.

Saif
grid3_brbpja.png
 
Hi,

Thanks for the guidance regarding the above, although the goal is achieved but the management is seeking some changes as follows:

1. If the user click on Req.From 2-W/H Column, the value should come in the same column and check box box should be removed.
2. Similary, if the user click on Req.From Factory (Last column) the value of column (Remaining) should come in the last column and it should be replaced by check box.

Is it possible, please guide me.

Thanks

Saif

 
Hi,

Please check this image.

Thanks

Saif
grid4_ussnet.png
 
Each Column has it's main controlsource, I don't see how you could let the column for a boolfield display available stock or remaining.

So in short: it makes no real sense to me.

The idea to use Label1 to display an empty cell from Mike could be extended to add further labels to show whatever text you want. That would mean you could end up with a lot of labels per column 8 and 9, one for each value to display, and need a complex dynamicccurrentcontrol logic.

I would not do that. Then rather move the checkbox columns near to the Available Stock or Remaining columns.

Chriss
 
Yes Chris I agree with this.

Thanks

Saif
 
Thanks, Saif,

now the question is, whether it's harder to convince the management of this alternative idea, or to implement what they want.

More food for thought: If you do as they wish, a misclick is not reversible. Once the checkbox is gone, you can't uncheck it.

So, it's bad design. Misusing a column for two different things in general is bad design. On top of that blocking the way back is a bad design.
But I wouldn't tell them that, they could feel attacked. Arguing for the advantages of your solution, they'll see their error but feel consulted, not insulted.

It also matters what they think about you becoming proactive now and simply do it or get their consent, first.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top