چك باكس در ms flex grid

nima_dir

Active Member
سلام دوستان
من ميخواستم در ms flex grid يك ستون داشته باشم كه بتونه مثل چك باكس عمل كنه. يعني بتونم در اون تيك بزنم. آيا كلا" ميشه همچين كاري انجام داد. اگر ميشه لطفا" من را راهنمايي كنيد
متشكرم
 

saalek110

Well-Known Member
اگر در ويژوال بيسيك منظورتونه....

Add Checkbox to MSFlexGrid Control


PIC20032102055372497.jpg

.
 

saalek110

Well-Known Member
http://www.vbcity.com/forums/faq.asp?fid=6&cat=Grids#TID13208

کد:
Option Explicit 

Dim strChecked As String

کد:
Private Sub Form_Load() 
Dim i As Variant, ms_rows As Integer 
    ' Start building the Grid 

    ms_rows = 20 ' This is the number of rows to print out 
    With MSFlexGrid1 
        .Row = 0 
        .Col = 0 
        .Rows = ms_rows + 1 'We add 1 to ensure we get all the rows 
        .Cols = 2 
        .ColWidth(0) = 250 ' CheckBox column 
        .ColWidth(1) = 1440 ' Index column 
    End With 

    ' Now build the Grid 

    For i = 0 To 20 'm_rows - 1 
        With MSFlexGrid1 
                .Row = i: .Col = 0: .CellPictureAlignment = 4 ' Align the checkbox 
                Set .CellPicture = picUnchecked.Picture ' Set the default checkbox picture to the empty box 
                .TextMatrix(i, 1) = i 
        End With 
    Next 
End Sub


Next add this function, it is where all the work is done; 

Code:
Private Sub MSFlexGrid1_Click() 
Dim oldx, oldy, cell2text As String, strTextCheck As String 

    ' Check or uncheck the grid checkbox 
    With MSFlexGrid1 
        oldx = .Col 
        oldy = .Row 
        If MSFlexGrid1.Col = 0 Then 
            If MSFlexGrid1.CellPicture = picChecked Then 
                Set MSFlexGrid1.CellPicture = picUnchecked 
                .Col = .Col + 1 ' I use data that is in column #9, usually an Index or ID # 
                strTextCheck = .Text 
                strChecked = Replace(strChecked, strTextCheck & ",", "") 
                Debug.Print strChecked 
            Else 
                Set MSFlexGrid1.CellPicture = picChecked 
                .Col = .Col + 1 
                strTextCheck = .Text 
                strChecked = strChecked & strTextCheck & "," 
                Debug.Print strChecked 
            End If 
        End If 
        .Col = oldx 
        .Row = oldy 
    End With 
End Sub
 

جدیدترین ارسال ها

بالا