Results 1 to 9 of 9

Thread: [RESOLVED] Why the code sort also blank cell in msflexgrid

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Resolved [RESOLVED] Why the code sort also blank cell in msflexgrid

    Immagine1.gif is the default grid
    Immagine2.gif is wath i see after click on header cell column ORE

    my code:

    Code:
    Private Sub Form_Activate()
    
        Me.Text1.SetFocus
    
    End Sub
    Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    
        Dim C As Integer, R As Integer
    
        With MSFlexGrid1
    
            C = .col
            R = .row - 1
    
            .Redraw = False
    
            If .TextMatrix(R, C) = "GIORNI" And Button = vbLeftButton And Shift = 0 And Me.LGG1.Caption > "" Then
                .col = 4
                If strSort = 1 Then
                    .Sort = 2    'SortGenericDescending
                    strSort = 2
                Else
                    .Sort = 1    'SortGenericAscending
                    strSort = 1
                End If
            End If
    
            If .TextMatrix(R, C) = "ORE" And Button = vbLeftButton And Shift = 0 And Me.LGG1.Caption > "" Then
                .col = 1
                If strSort = 1 Then
                    .Sort = 2    'SortGenericDescending
                    strSort = 2
                Else
                    .Sort = 1    'SortGenericAscending
                    strSort = 1
                End If
            End If
    
            If .TextMatrix(R, C) = "%" And Button = vbLeftButton And Shift = 0 And Me.LGG1.Caption > "" Then
                .col = 3
                If strSort = 1 Then
                    .Sort = 2    'SortGenericDescending
                    strSort = 2
                Else
                    .Sort = 1    'SortGenericAscending
                    strSort = 1
                End If
            End If
    
            If .TextMatrix(R, C) = "PROGRESSO" And Button = vbLeftButton And Shift = 0 And Me.LGG1.Caption > "" Then
                .col = 3
                If strSort = 1 Then
                    .Sort = 2    'SortGenericDescending
                    strSort = 2
                Else
                    .Sort = 1    'SortGenericAscending
                    strSort = 1
                End If
            End If
    
            .Redraw = True
            
        End With
            
        Me.Text1.SetFocus
    
    End Sub
    Attached Images Attached Images   

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: Why the code sort also blank cell in msflexgrid

    Make sure you don’t have blank lines in the grid, then you don’t have these “problems”

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: Why the code sort also blank cell in msflexgrid

    Quote Originally Posted by Arnoutdv View Post
    Make sure you don’t have blank lines in the grid, then you don’t have these “problems”
    i fill the grid with:
    Code:
    Private Sub CMESI_Click()
    
        ClearFlex Me.MSFlexGrid1
        
        Call CLEAR_PICTURE
    
        Dim DATA As Date, M As Integer, N As Integer, PERC As Long, W As Integer, H As Integer, R As Integer
    
        M = Split(Me.CMESI.Text, "-")(0)
    
        With Me.MSFlexGrid1
        
           Me.LGG1.Caption = Day(DateSerial(ANNO, M + 1, 0))
           DoEvents
    
            .Redraw = False
    
            For D = 1 To Day(DateSerial(ANNO, M + 1, 0))
    
                DATA = (Format(DateSerial(ANNO, M, D), "dd/mm/yyyy"))
    
                .TextMatrix(D, 0) = DATA
    
                N = Int(Rnd() * ORE) + 1
    
                .TextMatrix(D, 1) = N
    
                .TextMatrix(D, 4) = CDbl(DATA)
    
                PERC = (N / ORE) * 100
    
                'Me.Picture1.Picture = LoadPicture("C:\Lavori_Vb6\CALENDARIO_LISTVIEW\IMG\VERDE_12.jpg")
    
                .row = D
                .col = 2
    
                W = .CellWidth / PERC
                'H = .CellHeight
    
                'If PERC > 0 Then
                '    P = N / PERC
                'Else
                '    P = 0
                'End If
    
                If PERC >= 66 And PERC <= 100 Then
                    Me.Picture1.Visible = True
                    Me.Picture1.Width = .CellWidth / W * 13.7
                    Set .CellPicture = Me.Picture1.Image
                    .CellPictureAlignment = flexAlignLeftCenter
                    Set Me.Picture1.Picture = Nothing
                    Me.Picture1.Visible = False
                End If
    
                If PERC >= 33 And PERC <= 66 Then
                    Me.Picture2.Visible = True
                    Me.Picture2.Width = .CellWidth / W * 13.6
                    Set .CellPicture = Me.Picture2.Image
                    .CellPictureAlignment = flexAlignLeftCenter
                    Set Me.Picture2.Picture = Nothing
                    Me.Picture2.Visible = False
                End If
    
                If PERC >= 0 And PERC <= 33 Then
                    Me.Picture3.Visible = True
                    Me.Picture3.Width = .CellWidth / W * 13.6
                    Set .CellPicture = Me.Picture3.Image
                    .CellPictureAlignment = flexAlignLeftCenter
                    Set Me.Picture3.Picture = Nothing
                    Me.Picture3.Visible = False
                End If
    
                .TextMatrix(D, 3) = PERC
    
            Next      
    
            .Redraw = True
    
        End With
    
        Me.Text1.SetFocus
    
    End Sub

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: Why the code sort also blank cell in msflexgrid

    But you should set number of rows to number of day’s in the current month. Then you won’t have blank rows

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: Why the code sort also blank cell in msflexgrid

    Quote Originally Posted by Arnoutdv View Post
    But you should set number of rows to number of day’s in the current month. Then you won’t have blank rows
    infact.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: Why the code sort also blank cell in msflexgrid

    Quote Originally Posted by Arnoutdv View Post
    But you should set number of rows to number of day’s in the current month. Then you won’t have blank rows
    peraphs i need to select,before, the range of cell in related column?

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: Why the code sort also blank cell in msflexgrid

    I believe the msFlexGrid can only sort on complete columns, thus all rows.
    You you have to set .Rows property to the right amount of lines (days) you need

  8. #8
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,048

    Re: Why the code sort also blank cell in msflexgrid

    here a sample of what Arnoutdv is telling you

    adapt the sample to your code
    Code:
    Private Sub Command1_Click()
            Dim nYear As Long
            Dim nMonth As Long
            Dim nDays As Long
            Dim LastDayOfMonth As Date
            Dim FirstDayOfMonth As Date
            Dim d As Date
            
            
            For nYear = 2022 To 2023
                For nMonth = 1 To 12
                   
                    LastDayOfMonth = DateSerial(nYear, nMonth + 1, 0)
                    FirstDayOfMonth = DateSerial(nYear, nMonth, 1)
                    
                    'get a Day count in that month
                    d = DateSerial(nYear, nMonth, 1)
                    nDays = Day(DateAdd("m", 1, d) - 1)
                
                    List1.AddItem ("First Day Of Month : " & Format(FirstDayOfMonth, "dddd dd.MM.yyyy"))
                    'get a Day Count of that Month
                    List1.AddItem ("Days in Month : " & nDays) '<--- for rows in Flexgrid
                    
                    List1.AddItem ("Last Day of Month  : " & Format(LastDayOfMonth, "dddd dd.MM.yyyy"))
                    List1.AddItem ("---------------------------------------------------------------------")
    
                Next nMonth
            Next nYear
    End Sub
    nice to see you try Luca
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: Why the code sort also blank cell in msflexgrid

    Quote Originally Posted by chrise View Post
    here a sample of what arnoutdv is telling you

    adapt the sample to your code
    Code:
    private sub command1_click()
            dim nyear as long
            dim nmonth as long
            dim ndays as long
            dim lastdayofmonth as date
            dim firstdayofmonth as date
            dim d as date
            
            
            for nyear = 2022 to 2023
                for nmonth = 1 to 12
                   
                    lastdayofmonth = dateserial(nyear, nmonth + 1, 0)
                    firstdayofmonth = dateserial(nyear, nmonth, 1)
                    
                    'get a day count in that month
                    d = dateserial(nyear, nmonth, 1)
                    ndays = day(dateadd("m", 1, d) - 1)
                
                    list1.additem ("first day of month : " & format(firstdayofmonth, "dddd dd.mm.yyyy"))
                    'get a day count of that month
                    list1.additem ("days in month : " & ndays) '<--- for rows in flexgrid
                    
                    list1.additem ("last day of month  : " & format(lastdayofmonth, "dddd dd.mm.yyyy"))
                    list1.additem ("---------------------------------------------------------------------")
    
                next nmonth
            next nyear
    end sub
    nice to see you try luca
    nice!

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