Is This Bug or i wrote a wrong code ?

1 posts, 0 answers
  1. Hengky
    Hengky avatar
    26 posts
    Member since:
    Sep 2015

    Posted 02 May Link to this post

    Hello i wanna ask about this ... 

    i have a button with this code 

       Private Sub BtnBaru_Click(sender As System.Object, e As System.EventArgs) Handles BtnBaru.Click

           xStatus = "NEW"

            MCCBRekening.Enabled = True
            Isi_MCCBRekening()

            TxtKodeSubRekening.Enabled = True
        End Sub

     

    and procedure Isi_MCCBRekening 

       Private Sub Isi_MCCBRekening()
            Dim TblMstRekening As DataTable

            TblMstRekening = ds.Tables.Add("Rekening")
            With TblMstRekening
                .Columns.Add("Kode", GetType(String))
                .Columns.Add("Nama", GetType(String))
            End With

            Using conn As New OleDbConnection(str)
                conn.Open()

                da = New OleDbDataAdapter("SELECT KodeRekening as Kode, NamaRekening as Nama FROM MstRekening ORDER BY KodeRekening", conn)
                ds = New DataSet
                ds.Clear()
                TblMstRekening.Rows.Add(New Object() {"", ""})

                da.Fill(TblMstRekening)
                da.Dispose()

                conn.Close()
            End Using

            With MCCBRekening
                .MultiColumnComboBoxElement.DropDownWidth = 500
                .DataSource = TblMstRekening
                .BestFitColumns()

                .EditorControl.EnableCustomFiltering = True

                .SelectedValue = ""
                .AutoFilter = True

                .DisplayMember = "Kode"
                .ValueMember = "Kode"
                .Text = ""

                Dim filter As New FilterDescriptor()
                filter.PropertyName = Me.MCCBRekening.ValueMember
                filter.[Operator] = FilterOperator.Contains
                Me.MCCBRekening.EditorControl.MasterTemplate.FilterDescriptors.Add(filter)
                MCCBRekening.MultiColumnComboBoxElement.EditorControl.EnableCustomFiltering = True

                AddHandler .MultiColumnComboBoxElement.EditorControl.CustomFiltering, AddressOf MCCBRekening_CustomFiltering
                AddHandler .KeyDown, AddressOf MCCBRekening_KeyDown

            End With
        End Sub
        Private Sub MCCBRekening_CustomFiltering(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCustomFilteringEventArgs)

            Dim element As RadMultiColumnComboBoxElement = MCCBRekening.MultiColumnComboBoxElement

            Dim textToSearch As String = MCCBRekening.Text
            If AutoCompleteMode.Append = (element.AutoCompleteMode And AutoCompleteMode.Append) Then
                If element.SelectionLength > 0 AndAlso element.SelectionStart > 0 Then
                    textToSearch = MCCBRekening.Text.Substring(0, element.SelectionStart)
                End If
            End If

            If String.IsNullOrEmpty(textToSearch) Then
                e.Visible = True

                For i As Integer = 0 To element.EditorControl.ColumnCount - 1
                    e.Row.Cells(i).Style.Reset()

                Next

                e.Row.InvalidateRow()
                Return
            End If

            e.Visible = False
            For i As Integer = 0 To element.EditorControl.ColumnCount - 1
                Dim text As String = e.Row.Cells(i).Value.ToString()
                If text.IndexOf(textToSearch, 0, StringComparison.InvariantCultureIgnoreCase) >= 0 Then
                    e.Visible = True
                    e.Row.Cells(i).Style.CustomizeFill = True
                    e.Row.Cells(i).Style.DrawFill = True
                    e.Row.Cells(i).Style.BackColor = Color.FromArgb(201, 252, 254)
                Else
                    e.Row.Cells(i).Style.Reset()

                End If
            Next
            e.Row.InvalidateRow()
        End Sub
        Private Sub MCCBRekening_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MCCBRekening.KeyDown
            With MCCBRekening
                If e.KeyCode = System.Windows.Forms.Keys.Enter Then
                    If .ValueMember <> "" Then
                        .SelectedValue = .EditorControl.CurrentRow.Cells(.ValueMember).Value
                    Else
                        .SelectedValue = .EditorControl.CurrentRow.Cells(.DisplayMember).Value
                    End If

                    .Text = .EditorControl.CurrentRow.Cells(.DisplayMember).Value.ToString()
                    .MultiColumnComboBoxElement.ClosePopup()
                    .MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.SelectAll()
                End If
            End With
        End Sub
        Private Sub MCCBRekening_DropDownClosed(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.RadPopupClosedEventArgs) Handles MCCBRekening.DropDownClosed
            If MCCBRekening.SelectedIndex <> -1 Then
                lblNamaRekening.Text = MCCBRekening.EditorControl.Rows(MCCBRekening.SelectedIndex).Cells(1).Value.ToString
                TxtKodeRekening.Text = MCCBRekening.EditorControl.Rows(MCCBRekening.SelectedIndex).Cells(0).Value.ToString
            Else
                TxtKodeRekening.Text = ""
                lblNamaRekening.Text = ""
            End If
        End Sub
        Private Sub MCCBRekening_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MCCBRekening.Validated
            If MCCBRekening.Text = "" Then
                TxtKodeRekening.Text = ""
                lblNamaRekening.Text = ""
            End If
        End Sub

    my question is :

    why if i click the button for the second time it's give me error message ... the "Kode" is not belong to TblMstRekening .... 

     

    how i  fix this thanks ... 

     

     

     

Back to Top