[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Comparing the values in 2 cells in a MSFLEXgrid control..

Posted on 2004-10-29
11
Medium Priority
?
265 Views
Last Modified: 2012-05-05
Hi ,

I have a flex grid control with 4 columns and I have to check wheather the value entered in 2nd column is greater than the value entered in the 3rd column of each row.

I am writing the code on the leavecell event but the code fires everytime I press a key. I want to execute it only when I leave the cell and move to another one or move the focus to another control.

My code is


Private Sub MSFlexGrid1_LeaveCell(index As Integer)
If MSFlexGrid1(index).Col = 3 Then
    If MSFlexGrid1(index).TextMatrix(MSFlexGrid1(index).Row, 2) > MSFlexGrid1(index).TextMatrix(MSFlexGrid1(index).Row, 3) Then
        MsgBox "Wrong Value"
    End If
End If
End Sub

Thanks,
0
Comment
Question by:swami_varahagir
[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
  • 5
11 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 12445965
how are you entering data into the flexgrid? MSFlexGrid has no Cell editing feature.

anyways, try putting your code in the RowColChange event. I am assuming that initally, column 2 or 3 has the focus. you may also have to code the LostFocus event

let me know how it turned out


0
 

Author Comment

by:swami_varahagir
ID: 12446493
In RowColchange event also it remains the same.

I am using Keypress and KeyUp events to put the value I typed in into the cells. It is not an edit box but made it a kind of.

Let me hv some guide lines how to approach it.

Thanks,
0
 
LVL 6

Expert Comment

by:PePi
ID: 12446866
i assume that you are using up, down, left & right arrow to move from one cell to another. can you show me your key_press and key_up codes so that i can have a better understanding on what you are doing?
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:swami_varahagir
ID: 12447028
These are the events I have written for the flex grid control.

Thanks,


Private Sub MSFlexGrid1_KeyPress(index As Integer, KeyAscii As Integer)
    Dim oldCol
    oldCol = MSFlexGrid1(index).Col
    MSFlexGrid1(index).Col = 0
       MSFlexGrid1(index).Col = oldCol
        If MSFlexGrid1(index).Col = 0 Or MSFlexGrid1(index).Col = 1 Then
            KeyAscii = 0
        End If
        If (KeyAscii = 8) Then
            If (Len(MSFlexGrid1(index).Text) > 0) Then
                MSFlexGrid1(index).Text = Left(MSFlexGrid1(index).Text, Len(MSFlexGrid1(index).Text) - 1)
            Else
                KeyAscii = 0
            End If
        ElseIf Len(MSFlexGrid1(index).Text) < 5 Then
        Select Case KeyAscii
            Case 48 To 57:
                MSFlexGrid1(index).Text = MSFlexGrid1(index).Text + Chr(KeyAscii)
            Case Else
                MsgBox "Only Numbers allowed"
        End Select
        End If
End Sub


Private Sub MSFlexGrid1_KeyUp(index As Integer, KeyCode As Integer, Shift As Integer)
    If Not (MSFlexGrid1(index).Col = 0 Or MSFlexGrid1(index).Col = 1) Then
        If KeyCode = 46 Then
            MSFlexGrid1(index).Text = ""
        End If
    End If
End Sub


Private Sub MSFlexGrid1_RowColChange(index As Integer)
If MSFlexGrid1(index).Col = 3 Then
    If MSFlexGrid1(index).TextMatrix(MSFlexGrid1(index).Row, 2) > MSFlexGrid1(index).TextMatrix(MSFlexGrid1(index).Row, 3) Then
        MsgBox "Wrong Value"
    End If
End If
End Sub
0
 
LVL 6

Expert Comment

by:PePi
ID: 12448392
try this:

Private Sub flexgrid_KeyPress(KeyAscii As Integer)
    If flexgrid.Col = 0 Or flexgrid.Col = 1 Then
        KeyAscii = 0
    End If
   
    Select Case KeyAscii
        Case 8
            If (Len(flexgrid.Text) > 0) Then
                flexgrid.Text = Left(flexgrid.Text, Len(flexgrid.Text) - 1)
            Else
                KeyAscii = 0
            End If
        Case 48 To 57
            If Len(flexgrid.Text) < 5 Then
                flexgrid.Text = flexgrid.Text + Chr(KeyAscii)
            Else
                KeyAscii = 0
            End If
        Case Else
            MsgBox "Only Numbers allowed"
    End Select
End Sub

Private Sub flexgrid_LeaveCell()
    With flexgrid
        If Val(.TextMatrix(.Row, 2)) > Val(.TextMatrix(.Row, 3)) Then
            MsgBox "Col 2 is > Col 3"
        ElseIf Val(.TextMatrix(.Row, 2)) < Val(.TextMatrix(.Row, 3)) Then
            MsgBox "Col 3 is > Col 2"
        Else
            MsgBox "Col 3 = Col 2"
        End If
    End With
End Sub
0
 

Author Comment

by:swami_varahagir
ID: 12463452
Hi Pepi,

This LeaveCell event does not work. I have tried it before , also submitted the method before. Plz find some other alternative.

Thanks for the suggetion.

Thanks,

0
 
LVL 6

Expert Comment

by:PePi
ID: 12464983
I've tested the code I've provided above and it works just fine. I think the problem you are having is that your code in the KeyPress event is a bit off. Try and change your KeyPress event code with the one I provided above. Now, using the up, down, left or right arrow will trigger the leavecell event.

let me know how it turned out.


0
 

Author Comment

by:swami_varahagir
ID: 12466588
Hi Pepi,

I modified the code as u have instructed bit the problem is every time I hit the key it fires the LeaveCell event.

If say cell2 contains 45 and I move to cell3 and try to enter something, it fires the leavecell event and then puts the va;ue into the cell.

I want it to check when I complete the data entry and navigate to another cell or change my focus to another control in the form.

Thanks,
0
 
LVL 6

Accepted Solution

by:
PePi earned 900 total points
ID: 12467463
even if you use leavecell or rowcolchange event, when set the focus on cell2 and move to cell3, those event will fire.

i have tested the code i gave you and when i type or enter numberic values, leavecell doesn't fire. did you change your flexgrid's KeyPress event codes to the above code?
0
 

Author Comment

by:swami_varahagir
ID: 12467934
Yes I did....

If you could zip it and send to my email it will; be appreciated.

swami_v3@yahoo.com.

Thanks
0
 
LVL 1

Expert Comment

by:atheekurrahman
ID: 12470896
compare the values for every event that cause the grid to lose focus.
i.e for
        form_click() , msflexgrid_click , and for all other controls in the form(buttons and stuff)

if u r using a text box to edit the grid then use this as well

Private Sub txtValueEditor_KeyDown(KeyCode As Integer, Shift As Integer)
   With flexgrid
      Select Case KeyCode
         Case 13   'ENTER
            .SetFocus
         Case 27   'ESC
            txtValueEditor.Visible = False
            .SetFocus
         Case 38   'Up arrow
            .SetFocus
            DoEvents
            .Row = IIf(.Row > .FixedRows, .Row - 1, .Row)
         Case 40   'Down arrow
            .SetFocus
            DoEvents
            .Row = .Row + 1
      End Select
   End With
End Sub
0

Featured Post

Technology Partners: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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