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!

Checkbox behavior

Status
Not open for further replies.

aysDude

Programmer
Jan 29, 2013
5
Hi there!

I'm really stuck and I need your help, guys.

I have two tables in DB - one with companies, the other one with countries. Companies table has FK to countries.
I have a grid with companies and the column with country, which is shown in combobox.

The problem is that the combobox of the first row in the grid just after the start of the program is empty. Which causes attempt to update database when focus is going somewhere else. Here is the screenshot:

grid.jpg


I've tried rowsourcetype fields and arrays - works equally.

Any hint is highly appreciated!
 
The first place I would start investigating is the Query results which are combining the 2 tables and which you are most likely using as the RowSource for the problematic ComboBox.

I'd check to see that a non-blank value is being returned for ID = 8 - your Grid shown above implies that is where the problem resides.

Good Luck,
JRB-Bldr

 
Wise advice. I've checked the database once again and there are no empty values. Just to be sure I've changed ComboBox back to Text and here is the result:
gridTextBox.jpg


Any other suggestions?
 
I've checked the database data table(s) once again and there are no empty values.

When you say that you have checked the data tables, do you mean that you checked the individual data tables?
Or that you checked the Query Result which I assume you used to combine the 2 tables into a single ComboBox RowSource.

If the Query was not returning what you expect, then that could be the source of the problem.

Good Luck,
JRB-Bldr
 
I just noticed something...

In the title of this posting you say Checkbox Behavior
But in the body of your first posting you say "ComboBox"

And your screen snapshots might imply that the data is being used in a ComboBox.

Not that it should make much difference, but for clarification, which is it that is problematic?

Good Luck,
JRB-Bldr
 
Yes, you are right, for some reasons I named the topic incorrectly, probably I was too exhausted fighting with this ComboBox. And yes, as it is seen on the picture it's a ComboBox.

Regarding the data. The grid takes data from the table pGrid.RecordSource='op_offshores', and the field with the country code (j_id) is taken from the table without substitution. In order to show country name instead of country ID, ComboBox is used, which uses data from the table with countries op_jurisdictions:
Code:
   .Column3.Header1.Caption = 'Jurisdiction'
   WITH .Column3
      .width = 100
      .ControlSource = 'op_offshores.j_id'
      .Bound=.T.
      .AddObject('Combo1','ComboBox') 
      .CurrentControl = 'Combo1'
      .Text1.Visible = .F.
      .RemoveObject('Text1')
** Apply supercombo to all rows in the column, not only the active one
      .Sparse=.F.
      WITH .Combo1
        .BoundColumn = 2
        .BoundTo = .T.
      	.ColumnCount = 2 
      	.ColumnWidths = '100,0'
      	.RowSourceType = 6 && Fields
      	.RowSource = 'op_jurisdictions.j_name,j_id'
      	.Style = 2  && - Dropdown List
      	.BorderStyle = 0
        .Enabled = .T.
        .Visible = .T.
      ENDWITH
    ENDWITH
    .RecordSource='op_offshores'
    .refresh()
    .Visible = .T.
 ENDWITH

I've checked slightly modified version of ComboBox with RowSourceType=5 - Arrays. Behavior was exactly the same - first row (which probably has focus) is empty, the rest are perfectly fine. On the screenshot from my second it is seen that j_id in the first three rows is the same and equals to 1, so I assume that the data quality is not the case here.

If you have any other ideas how to check the data or how to debug ComboBox I will be really happy to hear any of them.

Best regards,
Aleksejs
 
Try

Code:
      WITH .Combo1
        .BoundColumn = 2
        .BoundTo = [b].F.[/b]
      	.ColumnCount = 2 
      	.ColumnWidths = '100,0'
        [b].ControlSource = 'op_offshores.j_id'[/b]
      	.RowSourceType = 6 && Fields
      	.RowSource = 'op_jurisdictions.j_name,j_id'
      	.Style = 2  && - Dropdown List
      	.BorderStyle = 0
        .Enabled = .T.
        .Visible = .T.
      ENDWITH
This is in accordance with this sample:
Bye, Olaf.
 
Thanks, Olaf.

VFP forbids setting of ControlSource with following message:
Parent object will not allow this property setting for grid.column3.combo1.ControlSource. I beleive it's OK just because column3.ControlSource which is op_offshores.j_id should be derived to combo1.ControlSource.

Setting boundTo=.F. will cause incorrect behavior, after changing different then original value of ComboBox will change record in database in a wrong way. Instead of taking j_id from op_jurisdictions, it will take ListIndex of the List used by ComboBox. Here is a good description from 1001 Things you Wanted to Know About Visual FoxPro.

Your post made me thinking of playing around with GotFocus:
Code:
IF !EMPTY(op_offshores.j_id)
        This.Value = op_offshores.j_id
ELSE
        This.DisplayValue = This.List(1)
ENDIF

Unfortunately to do this I'll need to switch from run-time definition of Grid content to definition during design-time as I don't have a clue how to modify GotFocus during the runtime.

I'll try this and will write about the results.
 
Well, as I said, "Try".

There has to be something about it, because the sample in the KB article I linked to does set the controlsource and uses boundto =.f., but it asks you to set all these things at design time, so this is a difference. It also makes the relation via a char (abbreviated state) and not a numeric field.

Another thing, which surely works is setting a relation instead of binding. But then you'd need code in lostfocus to set the parent table field.

Good luck.

Bye, Olaf.
 
VFP forbids setting of ControlSource with following message:
Parent object will not allow this property setting for grid.column3.combo1.ControlSource. I beleive it's OK just because column3.ControlSource which is op_offshores.j_id should be derived to combo1.ControlSource.

In general, VFP ignores the ControlSource of the contained object (the combo box, in this case). It is the ControlSource of the column that's important. (I know this doesn't help answer your question; I'm just pointing out the reason for the error message.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hello Guys!

I've made a lot of tests. The worst that I can't get reproducible results :( I've tried different balance between what is defined during run time and design time. Finally, I've switched to definition of all the details during design time.

But whole setup is working not as expected. After the form loading only ids are shown. But if ComboBox gets focus, it shows what I need. If ComboBox got clicked it again shows correct list:

StrangeGrid.jpg


So it looks like almost finished but some tiny detail. Any ideas where is the place which spoils everything?
 
Unclear what's your situation now.

If you set a relation you can set the column controlsource to the related table's char field and have a combobox unbound and sparse=.T., so it only displays, when you click on that field. And then it should set the foreign key in it's valid event.

Bye, Olaf.
 
It sounds like you need to set the Sparse property to .F. - that's a property of the column containing the combo boxes.

But I'm not sure if you will like the result. Personally, I think you will find it better as it is. But try it and see.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top