Results 1 to 3 of 3

Thread: MSHFlexGrid showing wrong data when filled 2x

  1. #1

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    MSHFlexGrid showing wrong data when filled 2x

    Ok, I have a txt box and when the textbox text changes its supposed to run an sql statement to fill the mshflexgrid. Which it does. BUT when you search more than once (without closing the frm in between)then click a line in the flexgrid to select a record it gives you the data for the line above the one you clicked...

    Im thinking the mshflexgrid isnt resetting or something in between. I tried the refresh property, the redraw property, the clear & Clear structure properties, etc. I dont know what else I can do.

    Here is my code to fill the mshflexgrid...

    VB Code:
    1. Dim sConnect As String
    2.     Dim sSQL As String
    3.     Dim dfwConn As ADODB.Connection
    4.     Dim datPrimaryRs As New ADODB.Recordset
    5.        
    6.     'set strings
    7.     sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & frmlocation.Text1.Text & "';Persist Security Info=False"
    8.     sSQL = "select InsRecID, SpecID, Insurance, InsuranceID from DrsInsuranceList where SpecID like '" & Text7.Text & "'"
    9.  
    10.     ' open connection
    11.     Set dfwConn = New ADODB.Connection
    12.     dfwConn.Open sConnect
    13.    
    14.     'create a recordset using the provided collection
    15.     datPrimaryRs.CursorLocation = adUseClient
    16.     datPrimaryRs.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
    17.    
    18.     Set MSHFlexGrid1.DataSource = datPrimaryRs
    19.    
    20.     With MSHFlexGrid1
    21.     .ColWidth(0) = 250
    22.     .ColWidth(1) = 0
    23.     .ColWidth(2) = 1500
    24.     .ColWidth(3) = 1500
    25.     .ColWidth(4) = 1500
    26.     .ColAlignment(1) = 4
    27.     .ColAlignment(3) = 4
    28.     .ColAlignment(4) = 4
    29.     .ColAlignmentFixed = 4
    30.     .Row = 0
    31.     .Col = 2
    32.     .Text = "Specialist ID"
    33.     .Col = 3
    34.     .Text = "Insurance"
    35.     .Col = 4
    36.     .Text = "Insurance ID"
    37.     End With

    Ideas?
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  2. #2

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Re: MSHFlexGrid showing wrong data when filled 2x

    Ok... I semi-fixed it.

    I added a

    VB Code:
    1. .Row = .MouseRow + 1

    But I also had to add a "On error resume next" (Which im not happy about) because everytime I like past the last row in the grid it gave an error.
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: MSHFlexGrid showing wrong data when filled 2x

    I could not duplicate the problem using your code. Here is what I used against the Northwind database.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim sConnect As String
    3.     Dim sSQL As String
    4.     Dim dfwConn As ADODB.Connection
    5.     Dim datPrimaryRs As New ADODB.Recordset
    6.        
    7.     'set strings
    8.     sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\projects\northwind2002.mdb;Persist Security Info=False"
    9.     sSQL = "select CustomerId, CompanyName, Country, Region From Customers where CustomerId Like '" & Text1.Text & "'"
    10.  
    11.     ' open connection
    12.     Set dfwConn = New ADODB.Connection
    13.     dfwConn.Open sConnect
    14.    
    15.     'create a recordset using the provided collection
    16.     datPrimaryRs.CursorLocation = adUseClient
    17.     datPrimaryRs.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
    18.    
    19.     Set MSHFlexGrid1.DataSource = datPrimaryRs
    20.    
    21.     With MSHFlexGrid1
    22.     .ColWidth(0) = 250
    23.     .ColWidth(1) = 0
    24.     .ColWidth(2) = 2500
    25.     .ColWidth(3) = 1000
    26.     .ColWidth(4) = 800
    27.     .ColAlignment(1) = 4
    28.     .ColAlignment(3) = 4
    29.     .ColAlignment(4) = 4
    30.     .ColAlignmentFixed = 4
    31.     .Row = 0
    32.     .Col = 2
    33.     .Text = "Company Name"
    34.     .Col = 3
    35.     .Text = "Country"
    36.     .Col = 4
    37.     .Text = "Region"
    38.     End With
    39. End Sub
    40.  
    41. Private Sub MSHFlexGrid1_Click()
    42.     Debug.Print Me.MSHFlexGrid1.TextMatrix(Me.MSHFlexGrid1.MouseRow, 1), Me.MSHFlexGrid1.TextMatrix(Me.MSHFlexGrid1.MouseRow, 2)
    43. End Sub

    Is there any other code in other events that may be contributing to the problem?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width