ชุมชนคนรักภาษาเบสิค - Visual Basic Community

 ลืมรหัสผ่าน
 ลงทะเบียน
ค้นหา
ดู: 3098|ตอบกลับ: 2

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

[คัดลอกลิงก์]

13

กระทู้

46

โพสต์

327

เครดิต

Full Member

Rank: 3Rank: 3

เครดิต
327

แก้ไขครั้งสุดท้ายโดย 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)
อยากให้มันเปลี่ยนสีตามเงื่อนไขทั้งแถวเลยครับ

Q1.png

5

กระทู้

13

โพสต์

190

เครดิต

Member

Rank: 2

เครดิต
190
โพสต์ 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

13

กระทู้

46

โพสต์

327

เครดิต

Full Member

Rank: 3Rank: 3

เครดิต
327
 เจ้าของ| โพสต์ 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
ขออภัย! คุณไม่ได้รับสิทธิ์ในการดำเนินการในส่วนนี้ กรุณาเลือกอย่างใดอย่างหนึ่ง ลงชื่อเข้าใช้ | ลงทะเบียน

รายละเอียดเครดิต

ข้อความล้วน|อุปกรณ์พกพา|ประวัติการแบน|G2GNet.com  

GMT+7, 2024-4-26 08:15 , Processed in 0.228509 second(s), 5 queries , File On.

Powered by Discuz! X3.4, Rev.62

Copyright © 2001-2020 Tencent Cloud.

ตอบกระทู้ ขึ้นไปด้านบน ไปที่หน้ารายการกระทู้