Results 1 to 9 of 9

Thread: How to hide column in Flexgrid

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Bangalore,karnatak
    Posts
    10

    Post

    Hi,

    I am facing difficulty in hiding a column in Flex Grid. We are hiding the column by setting the colWidth(N) = 0 , since the AllowUserResizing is set to True , the user is able to see the hidden column.

    There is a property called ColIsVisible(N) which gives the status of the column , hidden or not.
    But this seems to be a read only property whereas in MSDN (help) it states that one can set/read the property.

    The version of flexgrid we are using is 6.00.8418.

    Could you please suggest as to how you hide a column in MSFLEXGRID.

    Note: The requirement is to allow the user to resize.

    Thank You.

  2. #2
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112

    Post

    Here's what I would do, but it would mean the AllowUserResize property will need to be set to False so the column remains hidden.

    msFlexGrid1.Colwidth(X) = 1
    msFlexGrid1.AllowUserResize = FALSE
    msFlexGrid1.WordWrap = TRUE

    I would then resize each row's height so that the Word Wrap facility displays all data in each cell. (This will remove any requirement to allow the user to resize the cells)

    This site gives more info on how to go about doing this.
    http://support.microsoft.com/support.../Q178/1/27.ASP

    Hope this helps.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Unfortunately, MsFlexGrid doesn't have visible property for every column, BUT....
    You can set it's Width to 0 (zero), to have that effect.

    MSFlexGrid1.ColWidth(1) = 0


    It will nake the second column hidden.

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

    Serge

    Software Developer
    Serge_Dymkov@vertexinc.com
    Access8484@aol.com
    ICQ#: 51055819


  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Bangalore,karnatak
    Posts
    10

    Post

    Thanks for you replies.

    But the above solution do not solve the problem.

    The requirement is to allow the user to resize the columns. The column is to be conditionally hidden. Setting the column width to zero still allows the user to resize the hidden column (which we don't want)

    Is there any other way to hide the columns in the flex grid.?

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try using the MouseMove Event to Calculate which Column the Pointer is over, then Disable the Resizing Dynamically Depending on the Width of the Cell, where Zero Width Depicts a Disabled/Hidden Column eg.
    Code:
    Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim iCell As Integer
        With MSFlexGrid1
            For iCell = 0 To .Cols - 1
                If x >= .ColPos(iCell) And x <= .ColPos(iCell) + .ColWidth(iCell) Then Exit For
            Next
            If iCell < .Cols Then
                If (x - .ColPos(iCell)) < (.ColWidth(iCell) / 2) Then
                    iCell = iCell - 1
                    If iCell < 0 Then iCell = 0
                End If
                .AllowUserResizing = IIf(.ColWidth(iCell) > 0, flexResizeColumns, flexResizeNone)
            End If
        End With
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Bangalore,karnatak
    Posts
    10

    Post

    Hi Aaron,

    I did try with the code you sent but does'nt solve the problem.

    Say i have 5 columns and I hide the 3&4th column ,in the form load event by setting the col width of 3&4 to Zero.)

    Now in the mouse move event what i can do is if .mousecol = 3 then

    .colwidth(3) = 0

    endif

    This does solve the problem when the user clicks on the header row (col3) and pulls it holding the mouse button (down). once he moves out of the column then the mouse move event fires. but if he does'nt move the mouse outside the header row then the column gets resized and ends up showing the hidden column.

    Hope somehow i could muddle thru this.


  7. #7
    Junior Member
    Join Date
    Apr 1999
    Location
    Bangalore, KA, India
    Posts
    18

    Post

    It seems that the MouseMove event of the grid is not triggering correctly when the user drags the hidden (.colwidth =0) column. Therefore we have to use an external event to set the colwidth to 0. So I've used a timer control. In the following example, the 3rd column is hidden. The flex grid name is msgDetails.

    Private Sub Timer1_Timer()

    With msgDetails

    If .Redraw = False Then

    .Redraw = True

    End If

    If .ColWidth(3) <> 0 Then

    .Redraw = False
    .ColWidth(3) = 0

    End If

    End With

    End Sub



  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    I Created 5 Columns, Hid the 3rd and 4th Columns and couldn't resize them using the Code I posted.
    Are you sure you copied the Code I posted Exactly into the Correct Event?

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Bangalore,karnatak
    Posts
    10

    Post

    Hi Aaron,

    Thanks for UR help.

    After some R & D we have come to a conclusion that in Flexgrid one can hide the columns provided the columns that u hide lies between the first and last column.
    i.e: by setting colwidth(n)=0 .

    If you hide columns in the beginning or at the end then the user can resize it by pulling it out.

    Thanks once again

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