Results 1 to 8 of 8

Thread: MshFlexgrid in vb 6.0

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    77

    MshFlexgrid in vb 6.0

    Hi,

    I am not able to get entire rows as per my access database in MSHFlexgrid, can anyone please suggest

    Access DB example:

    WORD MEANING
    Deprive Not allow to have: to prevent somebody from having somethingTake away: to take something away from somebody; Depose: to depose somebody from high rank office

    Below is my code:
    Code:
    Set oRs = oConn.Execute(sql)
    
        mfgViewData.Clear
        mfgViewData.Rows = 2
        mfgViewData.Cols = 2
        mfgViewData.TextMatrix(0, 0) = "WORD"
        mfgViewData.TextMatrix(0, 1) = "MEANING"
        
        mfgViewData.ColWidth(0) = 1500
        mfgViewData.ColWidth(1) = 4000
        
        With oRs
        Do While oRs.EOF = False
            mfgViewData.AddItem ""
            mfgViewData.TextMatrix(mfgViewData.Rows - 2, 0) = .Fields("WORD")
            mfgViewData.TextMatrix(mfgViewData.Rows - 2, 1) = .Fields("MEANING")
        .MoveNext
        Loop
    End With
    Is there any oother way to view the data
    db:access
    application: vb 6.0

    Thanks in advance

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MshFlexgrid in vb 6.0

    Try adding the items like this.
    Code:
    Do While oRs.EOF = False
            mfgViewData.AddItem .Fields("WORD") & vbTab & .Fields("MEANING")
        .MoveNext
        Loop
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    77

    Re: MshFlexgrid in vb 6.0

    i tried ur code...but was not successfull..
    actually can we get the data in MsFlexgrid in multple lines? as the data is coming in single line andmost of the data is gettng missed..

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: MshFlexgrid in vb 6.0

    Is all of the data in a single record in the database?

    If so, then you would need to parse it into individual lines prior to adding it to your grid.

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: MshFlexgrid in vb 6.0

    If the problem is the text being too long for the cell then you could implement Wordwrapping, like this:
    Code:
        Dim lOriginalRowHeight As Long, lRowsNeeded As Long, lAux As String
        
        Set oRs = oConn.Execute(Sql)
        
        With mfgViewData
            .Clear
            .Rows = 2
            .Cols = 2
            .TextMatrix(0, 0) = "WORD"
            .TextMatrix(0, 1) = "MEANING"
        
            .ColWidth(0) = 1500
            .ColWidth(1) = 4000
            .WordWrap = True
            lOriginalRowHeight = .RowHeight(mfgViewData.Rows - 1)
    
            Do While Not oRs.EOF
                mfgViewData.AddItem vbNullString
                lAux = IIf(IsNull(oRs.Fields("MEANING")), vbNullString, oRs.Fields("MEANING"))
                lRowsNeeded = Fix(Me.TextWidth(lAux) / .ColWidth(1)) + 1
                .TextMatrix(mfgViewData.Rows - 2, 0) = oRs.Fields("WORD")
                .TextMatrix(mfgViewData.Rows - 2, 1) = lAux
                .RowHeight(mfgViewData.Rows - 2) = lOriginalRowHeight * lRowsNeeded
                
                oRs.MoveNext
            Loop
        End With
    The only problem you might have here is TextWidth(), it seems it's truncated when the string contains CR (Carriage return / jump to next line), does your column MEANING contains carriage returns?

    EDIT: in order for TextWidth to work the Form's and the Flexgrid's Font should be the same (Same FontName, size, style..)
    Last edited by jcis; Apr 27th, 2010 at 08:41 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    77

    Re: MshFlexgrid in vb 6.0

    yeah it contains carriage returns..

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    77

    Re: MshFlexgrid in vb 6.0

    Hey i tried with your code and did some changes..it is working now..
    Thanks a lottttttttttttttttttttt for your help..

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: MshFlexgrid in vb 6.0

    About the problem with CR now i see it can be solved by using TextHeight here are the changes needed..
    Code:
        Dim lOriginalRowHeight As Long, lRowsForWidthNeeded As Long, lRowsForHeightNeeded As Long, lAux As String
        Set oRs = oConn.Execute(Sql)
        
        With mfgViewData
            .Clear
            .ScrollTrack = True
            .Rows = 2: .Cols = 2
            .TextMatrix(0, 0) = "WORD"
            .TextMatrix(0, 1) = "MEANING"
            .ColWidth(0) = 1500
            .ColWidth(1) = 4000
            .WordWrap = True
            lOriginalRowHeight = .RowHeight(0) - 40
            
            Do While Not oRs.EOF
                mfgViewData.AddItem vbNullString
                If Not IsNull(oRs.Fields("MEANING")) Then
                    lAux = oRs.Fields("MEANING")
                    lRowsForWidthNeeded = Fix(Me.TextWidth(lAux) / .ColWidth(1)) + 1
                    lRowsForHeightNeeded = Me.TextHeight(lAux) / Me.TextHeight(vbNullString)
                    .TextMatrix(mfgViewData.Rows - 2, 0) = oRs.Fields("WORD")
                    .TextMatrix(mfgViewData.Rows - 2, 1) = lAux
                    .RowHeight(mfgViewData.Rows - 2) = lOriginalRowHeight * lRowsForWidthNeeded * lRowsForHeightNeeded + 40
                End If
                oRs.MoveNext
            Loop
        End With
    Last edited by jcis; Apr 27th, 2010 at 11:02 AM.

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