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

MSHFLEXGRID: row above the one I click gets selected 1

Status
Not open for further replies.

Overdoos

IS-IT--Management
May 31, 2000
79
0
0
BE
Is there an 'expert' in the field of the MSHFLEXGRID-object available?

The problem I have for my project is that, whenever I click a cell in my MsHFlexGrid, the cell above the one I click gets selected.

However, if the flexgrid containes so many lines that the vertical scrollbar shows up -and- I scroll down, this gets fixed. I don't know why this might be...

I did not define a click-event for this flexgrid, so nothing in there should be messing stuff up... the rest of the relevant code is below:

Code:
Public Sub FillHflexGrid(ByVal language As String)
  'defining variables
  Dim lStrSql As String
  Dim lTeller As Variant
  
  ' ------------------------
  ' Composing the SQL-string
  ' (colLang is a translation-collection)
  ' ------------------------
  lStrSql = "select "
  lStrSql = lStrSql & "row_id, "
  lStrSql = lStrSql & "datemaj as " & colLang("_DATEMAJ") & ", "
  lStrSql = lStrSql & "code as " & colLang("_CODE") & ", "
  lStrSql = lStrSql & "langue as " & colLang("_LANGUE") & ", "
  lStrSql = lStrSql & "quantite as " & colLang("_QUANTITE") & ", "
  lStrSql = lStrSql & "facture as " & colLang("_FACTURE") & ", "
  lStrSql = lStrSql & "datefac as " & colLang("_DATEFAC") & ", "
  lStrSql = lStrSql & "round(prixu, 2) as " & colLang("_PRIXU") & ", "
  lStrSql = lStrSql & "round(prixt, 2) as " & colLang("_PRIXT") & ", "
  lStrSql = lStrSql & "paye as " & colLang("_PAYE")
  lStrSql = lStrSql & " from abocom where noabo = " & lngAboNumber
  lStrSql = lStrSql & " order by datemaj"
  
  ' -----------------------------------------
  ' Composing and Showing the actual FlexGrid
  ' -----------------------------------------
  With frmAbnMain
    dbOpen = IIf(Not dbOpen, OpenAdoConnection(lStrSql), dbOpen)

    Set .hfgDetails.Recordset = adoRecordset
  
    .hfgDetails.ColWidth(0) = 400 'eerste kolom zijn enkel knopjes.
    
    ' adjusting the width of the columns based upon the header-text
    For lTeller = 1 To .hfgDetails.Cols - 1
      .hfgDetails.ColWidth(lTeller) = Len(.hfgDetails.ColHeaderCaption(0, lTeller)) * 100
    Next lTeller
    
    ' enable resize
    '.hfgDetails.ColAlignment
  
    dbOpen = IIf(dbOpen, CloseAdoConnection, dbOpen)
    
    ' hide the row_id
    frmAbnMain.hfgDetails.ColWidth(1) = 0
    ' hide the 'price per unit'
    frmAbnMain.hfgDetails.ColWidth(8) = 0
    ' hide the 'total'
    frmAbnMain.hfgDetails.ColWidth(9) = 0
    
    'frmAbnMain.hfgDetails.Cols = frmAbnMain.hfgDetails.Cols - 1
  
  End With
End Sub


Private Sub hfgDetails_RowColChange()
  With frmAbnMain
    If .hfgDetails.Rows > 1 Then
      ' place the row_id of the clicked command in the global variable
      lngCurrentCommand = .hfgDetails.TextMatrix(.hfgDetails.Row, 1)
      
      ' fill the detail-screen of the command with details.
      .txtComDateMaj.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 2)
      .txtComCode.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 3)
      .txtComLangue.Text = Short2Long("language", .hfgDetails.TextMatrix(.hfgDetails.Row, 4))
      .txtComQuant.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 5)
      .txtComFacture.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 6)
      .txtComDateFac.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 7)
      .txtComPrixu.Text = Round(Replace(.hfgDetails.TextMatrix(.hfgDetails.Row, 8), ".", ","), 2)
      .txtComPrixt.Text = Round(Replace(.hfgDetails.TextMatrix(.hfgDetails.Row, 9), ".", ","), 2)
      .txtComPaye.Text = .hfgDetails.TextMatrix(.hfgDetails.Row, 10)
      
      ' de focus naar het flexgrid toetrekken
      .hfgDetails.SetFocus
      ' de eerste lijn van de flexgrid highlighten
      .hfgDetails.Col = 0
      .hfgDetails.ColSel = .hfgDetails.Cols - 1
      ' refresh the flexgrid to keep the screen up-to-date
      .hfgDetails.Refresh
    End If
  End With
End Sub

--
There's no place like 127.0.0.1
 
Try adding:

.hfgDetails.row = .hfgDetails.rowsel

before:

.hfgDetails.ColSel = .hfgDetails.Cols - 1

Nick
 
I'm sorry Forri but that didn't help. The strange behaviour hasn't changed.

Any other ideas?
 
Hi

Have u cehcked the Selection Mode propery of your grid???
Make it Free Selection and try then,

HTH

Gazal
 
Hi Overdoos..

Although it's almost a month after your post, i guess u may still be reading this. So this may be of help, that is if you haven't found the solution of course.

I had the same problem and as far as i can understand it is related to the fact that although the data grid control is data bound, the first row (the fixed one) does not actually exist in the recordset. So your recordset does contain more records than those displayed in the grid. Under such circumstances if you (re)bind the grid at *run-time*, you will get "a mouse click displacement" equal to the number of the grid's fixed rows. If you scroll the grid, the problem automatically dissappears because the scrollbar's max and min values are "re-calibrated".

To replicate the error, i used a independent recordset (there is no database and the structure of the object is created at runtime). Having changed the data of the record set (just try to delete or add new records), you may try to refresh the data presented in the grid with the following code:

----------------------------------------------------
Set DataGrid.DataSource = Nothing
Set DataGrid.DataSource = DataProvider

(or via .refresh when u have a database)

----------------------------------------------------

This will actually cause the problem which will remain until you scroll the window. Instead, you may try this code:


----------------------------------------------------
Set DataGrid.DataSource = Nothing
DataGrid.FixedRows = 0
DataGrid.AddItem "Dummy"
'Add dummy row for headers
DataGrid.FixedRows = 1
Set DataGrid.DataSource = DataProvider
----------------------------------------------------


This will "refresh" the minumum and the maximum values of the scrollbar and thus fix the error.

I am not sure whether i can explain why this is happening. I guess it is just one more of the annoying MS bugs.

Let me know if that helped.
 
GothicCrusader,

I pushed out the program I needed that flexgrid for a couple of weeks ago after making exactly the same changes as you decribe here. So, it all worked, but not really the way I had hoped for.

I'm rewarding you with a star though because I failed to post the solution where you did. This, my friend, is very noble and might be very useful to those that come after. A well earned star is yours and a big thanks from my side.

kind regards,
OverdooS
 
You are welcome OverdooS and thanks for the star;)

This is a really annoying bug!:O

Let's hope this will be a helpful reference for the others:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top