Monday, July 4, 2016

Filter DataGridView VB.NET

        Try
            Dim dv As New DataView(dtable)
            dv.RowFilter = String.Format("fname like '%{0}%'", TextBox9.Text)
            DataGridView1.DataSource = dv
        Catch ex As Exception
            MessageBox.Show(ex.Message, "filter")
        End Try

Fill ComboBox ; SQL Server ; VB.NET

        Try
            myconn = New SqlConnection(My.Settings.testsettings)
            myconn.Open()
            mycmd = New SqlCommand("select * from test1", myconn)
            dr = mycmd.ExecuteReader

            While dr.Read
                ComboBox1.Items.Add(dr("fname"))

            End While

        Catch ex As Exception
            MessageBox.Show(ex.Message, "cbox")

        End Try

        myconn.Close()
        mycmd.Dispose()
        dr.Close()

Search from DataGridView VB.NET

        Dim i As Integer = 0
        Dim rcount As Integer = 0
        Dim ifound As Boolean = False

        Try
            rcount = DataGridView1.RowCount
            DataGridView1.MultiSelect = False

            While i < rcount And ifound = False
                DataGridView1.Rows(i).Selected = True

                If DataGridView1.SelectedRows(0).Cells(1).Value = TextBox10.Text Then
                    DataGridView1.CurrentCell = DataGridView1(0, i)
                    ifound = True

                else
                    i = i + 1
                End If

                

            End While
        Catch ex As Exception
            MessageBox.Show(ex.Message, "found")
        End Try

        If ifound = False Then MessageBox.Show("no record found", "")