my2alee โพสต์ 2019-12-18 15:59:44

[VB6] - กำหนดสีให้กับ MSFlexGrid ทั้งแถวตามเงื่อนไข

แก้ไขครั้งสุดท้ายโดย my2alee เมื่อ 2019-12-18 16:04

    fgData.Rows = RS.RecordCount + 1
    lblCount.Caption = "จำนวน : " & RS.RecordCount & " รายการ"
      If blnSearch = True And RS.RecordCount > 0 Then
            lblCountData.Caption = "ผลการค้าหา : " & RS.RecordCount & " รายการ"
      End If
    RS.MoveFirst
    item = 1
    Do Until RS.EOF
      With fgData
            .TextMatrix(item, 0) = RS("new_id")
            .TextMatrix(item, 1) = item
            .TextMatrix(item, 2) = "" & RS("hn")
            .TextMatrix(item, 3) = "" & RS("full_name")
            .TextMatrix(item, 4) = "" & RS("q_no")
            .TextMatrix(item, 5) = "" & Right(RS("q_time"), 8)
                  If RS("status_call") = "0" Then
                        strStatusCall = "ยังไม่เรียกคิว"
                  ElseIf RS("status_call") = "1" Then
                         strStatusCall = "เรียกแล้ว"
                  ElseIf RS("status_call") = "2" Then
                        strStatusCall = "เรียกแล้ว-ไม่มา"
                  End If
            .TextMatrix(item, 6) = "" & strStatusCall
                            'แสดงสี*** ตามเงื่อนไข
                            If RS("status_call") = "0" Then 'Hilite new row in red
                              .Col = 6
                              .Row = item
                              .CellBackColor = vbRed
                              .CellFontBold = True
                           ElseIf RS("status_call") = "1" Then 'Hilite new row in red
                              .Col = 6
                              .Row = item
                              .CellBackColor = vbGreen
                              .CellFontBold = True
                            ElseIf RS("status_call") = "2" Then 'Hilite new row in red
                              .Col = 6
                              .Row = item
                              .CellBackColor = vbYellow
                              .CellFontBold = True
                           End If
                           '********************
      End With
      item = item + 1
      RS.MoveNext
    Loop
ผมแนบรูปมาให้ด้วยครับ ตอนนี้ผมทำได้แค่กำหนดตำแหน่ง Col ไป (จากรูปคือ Col 6)
อยากให้มันเปลี่ยนสีตามเงื่อนไขทั้งแถวเลยครับ

kai โพสต์ 2019-12-18 17:36:10

แก้ไขครั้งสุดท้ายโดย kai เมื่อ 2019-12-18 22:50

If RS("status_call") = "0" Then 'Hilite new row in red
                           '    .Col = 6
                            '    .Row = item
                            '    .CellBackColor = vbRed
                            '    .CellFontBold = True
'********** ใส่ Loop ชุดนี้เข้าไปแมนครับ
                        For i = 1 To .cols
                              .Col = i
                              .Row = item
                              .CellBackColor = vbRed
                              .CellFontBold = True
                        next

my2alee โพสต์ 2019-12-19 16:18:20

แก้ไขครั้งสุดท้ายโดย my2alee เมื่อ 2019-12-20 09:52

kai ตอบกลับเมื่อ 2019-12-18 17:36
If RS("status_call") = "0" Then 'Hilite new row in red
                           '    .Col = 6
    ...
ขอบคุณมากครับ จากสคริปที่พี่ให้มาใช้ได้เลยครับ แต่ผมมาปรับเล็กน้อย
   For i = 1 To .Cols
             If i > 6 Then i = 0: Exit For'คอลัมป์แสดงผลผมกำหนด .Cols = 7 (ซ่อน Primary ไว้ 1 col) พอ loop เกิน 6 ก็ให้ออกจาก for ไว้เลย ถ้าไม่ใส่มัน error
                  .Col = i
                  .Row = item
                  .CellBackColor = vbRed
                  .CellFontBold = True
            Next
หน้า: [1]
ดูในรูปแบบกติ: [VB6] - กำหนดสีให้กับ MSFlexGrid ทั้งแถวตามเงื่อนไข