Results 1 to 5 of 5

Thread: Clearing grids [RESOLVED]

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Clearing grids [RESOLVED]

    Is it possible to use MSFlexGrid1.Clear to clear JUST the text in all the cells without changing the values of CellAlignment? Otherwise I have to delete the text of each cell individually looping over all the rows and columns. I mean is there any API trick or something?
    Last edited by krtxmrtz; May 14th, 2004 at 07:50 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    I'm not sure if it will work, but have you tried setting the .Clip property to an empty string? I'm think it only affects the text, not any formatting.

    eg:
    VB Code:
    1. With MSFlexGrid1
    2.   .Row = 0
    3.   .Col = 0
    4.   .RowSel = .Rows - 1
    5.   .ColSel = .Cols - 1
    6.   .Clip = ""
    7. End With

    if an empty string only clears the first cell (but in the way you want), you will need to set up a string with tabs/CR's for each cell (which you can use the String function to create).

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Well, it works but I can't figure out how to build that string. I've tried something like
    VB Code:
    1. Dim s As String
    2.     With MSFlexGrid1
    3.         s = String(.Cols - 1, vbTab)
    4.         s = s & vbCr
    5.         s = String(.Rows - 2, s)
    6.         s = s & String(.Cols - 1, vbTab)
    7.         .Row = 0
    8.         .Col = 0
    9.         .RowSel = .Rows - 1
    10.         .ColSel = .Cols - 1
    11.         .Clip = s
    12.     End With
    but this just clears the first row. Looks like the vbCr character is ignored.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    I've had a little play, but I forgot that the String function can only work with one character. What I originally thought of (doesnt work!) was this:
    VB Code:
    1. s = String(.Rows - 1, String(.Cols - 1, vbTab) & vbCr)

    And here's a working solution:
    VB Code:
    1. Dim i As Long
    2.         s = ""
    3.         For i = 1 To .Rows
    4.           s = s & String(.Cols - 1, vbTab) & vbCr
    5.         Next i

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Thumbs up

    ...so that's why!? Thank you.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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