?
Solved

How do DataGrid and ComboBox Interact?

Posted on 2003-02-25
9
Medium Priority
?
280 Views
Last Modified: 2010-04-07
I am using VB 6 and MS DataGrid control 6.0 with an Oracle database.

I have not worked with a datagrid before and I inherited this program from a person who is no longer with the company.

On the field I am having a problem with, the datagrid (dgParams) is working with a combobox (cmbSeismicCategory).

PROBLEM:
User simply clicks on the dgParams datagrid column that has the cmbSeismicCategory combobox when the value is null.  Without the user even selecting a value in the combobox, the value changes in the database to last
value on the combobox selection list.

I have isolated where the problem is occurring but do not understand what is happening and why.

OBSERVATIONS:
There is not a default in the Oracle database so I focused on the program.

I am following dgParams.Text and cmbSeismicCategory.Text through the program.  Reference the code below.  Through LINE 3, dgParams.Text and cmbSeismicCategory.Text both equal null.

After LINE 3, the program moves to LINE 11 then dgParams.Text equals null and cmbSeismicCategory.Text equals the last value on the combobox selection list which happens to be "N/A".

Of course, LINE 12 changes dgParams.Text to "N/A" and all this has occurred with the user simply clicking on the datagrid column.

LINE 1  Private Sub FillCombo(Temp As ComboBox, StrValue As String)
LINE 2      Dim i As Integer
LINE 3      Temp.ListIndex = Temp.ListCount - 1
LINE 4      For i = 0 To Temp.ListCount - 1
LINE 5          If Temp.List(i) = StrValue Then
LINE 6              Temp.ListIndex = i
LINE 7              Exit For
LINE 8          End If
LINE 9      Next i
LINE 10 End Sub

LINE 11 Private Sub cmbSeismicCategory_Click()
LINE 12     dgParams.Text = cmbSeismicCategory.Text
LINE 13 End Sub

I appreciate your suggestions.
0
Comment
Question by:Kevin_Christensen
[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
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:wehoit
ID: 8023305
You'll have to post more of the code for more help...

You write:
"Of course, LINE 12 changes dgParams.Text to "N/A" and all this has occurred with the user simply clicking on the datagrid column."

This tells me that something is going on prior to getting to the Sub you posted here.

The last value in the box is being selected in this Sub with this line (3):
Temp.ListIndex = Temp.ListCount - 1

If this combo only has "N/A" in it, then that is what is being selected.

Then, when you say the code moves from Line 3 to Line 11,
I'm not sure how this could happen. It should evaluate Line 4 first - it must be that the value for Temp.ListCount-1 is less than zero - meaning there's nothing in the "temp" list (the one sent via params) so the For loop is skipped.

What calls the "FillCombo" Sub?
My guess is the user clicking on the datagrid does that.
Look for the data grid's "click" or "selchange" event.
Or, just search for "FillCombo" throughout the code to determine where the call comes from...

0
 

Author Comment

by:Kevin_Christensen
ID: 8029296
You are correct, FillCombo() is called by dgParams_RowColChange() -- see code below...

The combobox list has 5 values in this order; SC-I, SC-II, SC-III, SC-IV, N/A.

After FillCombo LINE 3 Temp.ListIndex = -1 abd Temp.ListCount = 5

It seems that FillCombo LINE 3 triggers the combobox Click event and chsnges cmbSeismicCategory.Text to N/A.

BEGIN CODE:
Private Sub dgParams_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
If dgParams.Col = 6 Then
    Call FillCombo(cmbSeismicCategory, dgParams.Text)
    Call ShiftCombo(cmbSeismicCategory, 6)
Else
    cmbSeismicCategory.Visible = False
End If
If dgParams.Col = 5 Then
    Call FillCombo(cmbSafetyClass, dgParams.Text)
    Call ShiftCombo(cmbSafetyClass, 5)
Else
    cmbSafetyClass.Visible = False
End If


If Not IsInsert Then
    If Not IsEmpty(LastRow) Then
       If IsLocked Then Call Unlock_Record
         
       If adoRs.EOF Or adoRs.BOF Then
       Else
           If Not adoRs.EditMode = adEditAdd Then SetRefs
       End If
    End If
End If

End Sub
0
 
LVL 1

Accepted Solution

by:
wehoit earned 400 total points
ID: 8030183
I don't think I see the need for Line 3 at all.

Have you commented it out and run the project?

It looks like it's selecting the last value ("N/A") by default.

I would also consider changing the code to this:
LINE 1  Private Sub FillCombo(Temp As ComboBox, StrValue As String)
LINE 2      Dim i As Integer
..........<moved below>.............................
LINE 4      For i = 0 To Temp.ListCount - 1
LINE 5          If Temp.List(i) = StrValue Then
LINE 6              Temp.ListIndex = i
LINE 7              Exit For
LINE 8          End If
LINE 3      Temp.ListIndex = Temp.ListCount - 1
LINE 9      Next i
LINE 10 End Sub

This way, "N/A" is selected if nothing else is first.
0
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.

 

Author Comment

by:Kevin_Christensen
ID: 8035530
THANK YOU!  That worked.  I cannot find any negative impact to removing that line of code.

Though not a problem, I have another observation with this same combobox and if something quick comes to mind I would appreciate a suggestion.  When there are multiple rows displayed in the datagrid and if one row's combobox field has a value and another row is null, the combobox behaves this way.  Only when the combobox with a null value has the focus, the value from the other row is displayed, but does not change the data in the database.

Kevin

0
 
LVL 1

Expert Comment

by:wehoit
ID: 8035643
You kind of lost me on the last one.

Can you be a little more descriptive, and perhaps attach a screenshot?
0
 

Author Comment

by:Kevin_Christensen
ID: 8036459
How do you add an attachment?  I will try and expalain using text...  Otherwise for screenshots, you can contact me at rockserf@hotmail.com and I will e-mail them to you.

This is the same datagrid and combobox that you helped me with before, therefore the same code applies.

These values display in the datagrid when first viewing 3 records.

Column - Seismic Category
Row 1  - null
Row 2  - null
Row 3  - N/A

After clicking on row 3 then clicking on row 1, for example, these are the values that I see.

Column - Seismic Category
Row 1  - N/A
Row 2  - null
Row 3  - N/A

Then if I click on row 2...

Column - Seismic Category
Row 1  - null
Row 2  - N/A
Row 3  - N/A
 
Fortunately the values for rows 1 and 2 do not change in the database but the fact that N/A is dispalyed is confusing and misleading.

Thanks.
0
 
LVL 1

Expert Comment

by:wehoit
ID: 8036890
You list the display for some rows as "null".
Do you mean the combo boxes show nothing?
While the "N/A" reference is actual text, right?

And you're saying that just clicking on a 'row' changes the displayed text in the combos to 'N/A'?

Last, the problem is that clicking Row 2 swaps the displayed text between Rows 1 and 2?

OK - first, do this: In this Sub
Private Sub dgParams_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
If dgParams.Col = 6 Then
   Call FillCombo(cmbSeismicCategory, dgParams.Text)
...

display these vars (use a msgbox, or a text box or something to dump the values) We need to see what is being sent to the FillCombo Sub.
LastRow
LastCol
cmbSeismicCategory
dgParams.Text
0
 

Author Comment

by:Kevin_Christensen
ID: 8061300
The answer is YES to all of your questions.

Looking at LastRow, LastCol, cmbSeismicCategory.Text, and dgParams.Text where you suggested, yields the following:

Clicking Row 3 shows
  LastRow = 1
  LastCol = 0
  cmbSeismicCategory.Text = null
  dgParams.Text = N/A

Then clicking Row 1 shows
  LastRow = 3
  LastCol = -1
  cmbSeismicCategory.Text = N/A
  dgParams.Text = null

Then clicking Row 2 shows
  LastRow = 1
  LastCol = -1
  cmbSeismicCategory.Text = N/A
  dgParams.Text = null

I will be posting a new question for another problem I am having with this same datagrid, probably on Wednesday.  An opportunity for more points!
0
 
LVL 1

Expert Comment

by:wehoit
ID: 8062147
It's getting difficult to track now.

The Sub "dgParams_RowColChange" never uses the input val "LastCol", so I don't know why it's there.

Also, what does the sub "ShiftCombo" do?

Just from a debugging standpoint, I'd comment out the calls to "ShiftCombo" within "dgParams_RowColChange" and see if the values shown in the combos still get weird.

Also, when the value (ListIndex) in the combo changes, it should fire off the "change" or "click" event for that combo.
Perhaps that event is where the text changes again?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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