Hello,

I'm new in here and in vb too.

I have a problem to deleting selected row in Grid1 base on selected column in Grid

Take a look this screenshot below :

Name:  SS-Form.JPG
Views: 6114
Size:  108.2 KB

This code I have :

Code:
Private Sub InitGridPeriksa()
'This for generate Grid
    cIRowCount = 0
    With Grid
        .Clear
        .ClearStructure
        .Rows = 2
        .FixedRows = 1
        .FixedCols = 1
        .Cols = 8
        .ColSel = 7

        'Initialize the column size
        .ColWidth(0) = 435
        .ColWidth(1) = 1425
        .ColWidth(2) = 700
        .ColWidth(3) = 4900
        .ColWidth(4) = 1115
        .ColWidth(5) = 1115
        .ColWidth(6) = 500
        .ColWidth(7) = 500

        'Initialize the column name
        .TextMatrix(0, 0) = ""
        .TextMatrix(0, 1) = "TestLabID"
        .TextMatrix(0, 2) = "KdTestLab"
        .TextMatrix(0, 3) = "NmTestLab"
        .TextMatrix(0, 4) = "BiayaVIP"
        .TextMatrix(0, 5) = "Tarif"
        .TextMatrix(0, 6) = "TestLabFK"
        .TextMatrix(0, 7) = "PKFK"

        'Set the column alignment
        .ColAlignment(0) = vbLeftJustify
        .ColAlignment(1) = vbLeftJustify
        .ColAlignment(2) = vbLeftJustify
        .ColAlignment(3) = vbLeftJustify
        .ColAlignment(4) = vbRightJustify
        .ColAlignment(5) = vbRightJustify
        .ColAlignment(6) = vbLeftJustify
        .ColAlignment(7) = vbLeftJustify

    End With
End Sub

Private Sub InitGridTest()
'This for generate grid1
    cIRowCount1 = 0
    With Grid1
        .Clear
        .ClearStructure
        .Rows = 2
        .FixedRows = 1
        .FixedCols = 1
        .Cols = 6
        .ColSel = 5
        'Initialize the column size
        .ColWidth(0) = 435
        .ColWidth(1) = 1200
        .ColWidth(2) = 3000
        .ColWidth(3) = 2000
        .ColWidth(4) = 500
        .ColWidth(5) = 500

        'Initialize the column name
        .TextMatrix(0, 0) = ""
        .TextMatrix(0, 1) = "KdNilaiNormal"
        .TextMatrix(0, 2) = "NmTestLab"
        .TextMatrix(0, 3) = "NilaiNormal"
        .TextMatrix(0, 4) = "TestLabFK"
        .TextMatrix(0, 5) = "PKFK"

        'Set the column alignment
        .ColAlignment(0) = vbLeftJustify
        .ColAlignment(1) = vbLeftJustify
        .ColAlignment(2) = vbLeftJustify
        .ColAlignment(3) = vbLeftJustify
        .ColAlignment(4) = vbLeftJustify
        .ColAlignment(5) = vbLeftJustify

    End With

End Sub
This code for btnRemove ...

I want to delete selected row in Grid1 base on Selected Column in Grid ,,, please see screenshot !

Code:
Private Sub btnRemove_Click()

    Dim i As Integer
    Dim j As Integer

    'this code is function to get selected column data in grid
    CurrRow1 = getFlexPos(Grid, 6, NSDPeriksa.BoundText)
        
        
    'this code I get in here (VBForums) but this code is fail !!
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'this code fail to delete selected row in grid1 base on column in grid ... script out of range
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    For i = 1 To cIRowCount1 
        If Grid1.TextMatrix(i, 4) = CurrRow1 Then 'selected match column in grid1 base on grid
            Grid1.RowSel = i

            With Grid1 'the msflexgrid
                If .RowSel <> 0 Then 'check if there is a selected row
                    For j = .RowSel To .Rows - 2 'loop from selected row to the las row
                        .TextMatrix(j, 0) = .TextMatrix(j + 1, 0) 'set rows with 1 back
                        .TextMatrix(j, 1) = .TextMatrix(j + 1, 1)
                        .TextMatrix(j, 2) = .TextMatrix(j + 1, 2)
                        .TextMatrix(j, 3) = .TextMatrix(j + 1, 3)
                    Next j
                    .Rows = .Rows - 1 'make the rows 1 less
                Else
                    MsgBox "Selecet row to delete!!!", vbExclamation
                End If
            End With
        End If

    Next i
    
    
    'This code is OK to delete selected row in grid
    With Grid

        TxtBiaya(0).Text = TxtBiaya(0).Text - toNumber(Grid.TextMatrix(.RowSel, 5))
        TxtBiaya(0).Text = toMoney(TxtBiaya(0).Text)

        cIRowCount = cIRowCount - 1

        If .Rows = 2 Then Grid.Rows = Grid.Rows + 1
        .RemoveItem (.RowSel)
    End With


    btnRemove.Visible = False
    Grid_Click

End Sub
Please help !!!