Hi,
I want to create a Alternate Coloring in MsFlexGrid that using the Visual Basic Programming.
Here I attach a source code :
MsFlexGrid I give name : Flex

If Wt <= RsParts.Fields!Lowerlimit Then

                '***********************************************************
                '2. Section for create Color at 1 Column under REMARK

                Dim lngRow As Long
                Dim lngBack As Long
                Dim lngMax As Long
                Dim lngMin As Long

                    For lngRow = 1 To .Rows - 1
                    'default background color

                    LowerUpper = "This Part Weight is Less Than LowerLimit"

                    'check for important values
                    If Val(.TextMatrix(lngRow, 1)) >= lngMax Then

                            'important color
                            lngBack = vbRed             'Backolor
                            lngMin = vbYellow           'Font Color

                        End If

                        'select whole row
                          .Row = lngRow
                          .Col = 4                  'Column for REMARK
                          .RowSel = lngRow
                          .ColSel = .Cols - 2       'Setfocus at COLUMN NO. 4

                          'set the background color of the selected row
                          .CellBackColor = lngBack
                          .CellForeColor = lngMin
                          .CellFontBold = True

                        Next lngRow
                         ElseIf Wt >= RsParts.Fields!upperlimit Then
         ![Terminal_System.jpg](/attachments/large/4/642565f3dfd0c4f2a428cf3118847715.jpg "align-center")                                     LowerUpper = "This Part Weight is Greater Than UpperLimit"
           ' MsgBox LowerUpper

        End If
                   End With
Exit Sub

err_Handler:

    Select Case Err.Number
        Case 3021  ' no record
            If sk = 0 Then
                MsgBox "Part Number database is empty !", vbOKOnly + vbInformation
            End If
                        Case Else

                    MsgBox Err.Number & "  " & Err.Description, vbExclamation + vbOKOnly
    End Select

In this code, just colour at 1 Column only ; REMARK Section (Can refer at attachment).
I want to create alternate colour at next Row when calibrate by Weighing Machine (vbGreen and vbYellow) without changing colour under REMARK Section.

If I'm using the code at below :

'Dim Lajur As Long       'Row
        'Dim Baris As Long       'Col

         '   .Redraw = True
         '   For Lajur = 1 To .Rows - 1 Step 2
         '   For Baris = .FixedCols To .Cols - 1
         '   .Row = Lajur
         '   .Col = Baris
         '   .CellBackColor = vbYellow

         '           Next

         '               Next

         '               .Redraw = False

It to be as attachment No. 2 (Terminal Weighing 2.jpg).

Can anyone give some idea ?

Dani AI

Generated

you are close. In MSFlexGrid you can color any contiguous selection, so the trick is to stripe the whole row except the REMARK column, then (in a separate pass) color just that single REMARK cell based on limits. That way your alternation never overwrites the alert colors. the two screenshots likely looked identical because only the REMARK column was being colored; the rest of the row did not change.

Here is a compact pattern you can drop in. Replace remarkCol and the column used for weight as needed.

' Alternate row colors without touching REMARK column
With Flex
    Const remarkCol As Long = 4       ' your REMARK column index
    .Redraw = False
    .FillStyle = flexFillRepeat       ' apply props to the whole selection

    Dim r As Long, rowBack As Long
    For r = .FixedRows To .Rows - 1
        rowBack = IIf((r Mod 2) = 0, vbYellow, vbGreen)

        ' left side of REMARK
        If remarkCol - 1 >= .FixedCols Then
            .Row = r: .Col = .FixedCols
            .RowSel = r: .ColSel = remarkCol - 1
            .CellBackColor = rowBack: .CellForeColor = vbBlack
        End If

        ' right side of REMARK
        If remarkCol + 1 <= .Cols - 1 Then
            .Row = r: .Col = remarkCol + 1
            .RowSel = r: .ColSel = .Cols - 1   ' include last column
            .CellBackColor = rowBack: .CellForeColor = vbBlack
        End If
    Next

    ' Now color only the REMARK cell based on limits
    For r = .FixedRows To .Rows - 1
        .Row = r: .Col = remarkCol
        If Val(.TextMatrix(r, 1)) <= LowerLimit Then
            .CellBackColor = vbRed: .CellForeColor = vbYellow: .CellFontBold = True
        ElseIf Val(.TextMatrix(r, 1)) >= UpperLimit Then
            .CellBackColor = vbRed: .CellForeColor = vbWhite: .CellFontBold = True
        End If
    Next

    .Redraw = True
End With

Notes:

  • Use .Cols - 1 (not .Cols - 2) so you do not miss the last column.
  • Do the striping first, then the REMARK logic, so the alert colors always win on that column.

I've looked at attachments 1 and 2 and found no difference. Help me out here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.