Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Populate One Column on DataGridView with Value from TextBox

$
0
0

Hello,

I am using the following code to populate DataGridView.

        dt1 = New SqlDataAdapter("select empid, school, year, title, id from emp_education where empid='" & txt_EmpID.Text & "'", con1)
        cb1 = New SqlCommandBuilder(dt1)
        ds1 = New DataSet
        dt1.Fill(ds1, "emp_education")
        dgv_Education.DataSource = bs1
        bs1.DataSource = ds1
        bs1.DataMember = ds1.Tables("emp_education").TableName
        bn_Educ.BindingSource = bs1
        Dim i As Integer
        With dgv_Education
            .Columns(0).Width = 100
            .Columns(0).HeaderText = "Employee ID"
            .Columns(1).Width = 200
            .Columns(1).HeaderText = "School"
            .Columns(2).Width = 100
            .Columns(2).HeaderText = "Year"
            .Columns(3).Width = 100
            .Columns(3).HeaderText = "Title"
            .Columns(4).Width = 100
            .Columns(4).HeaderText = "ID"
            .Columns(4).Visible = False

            .Rows(0).Cells("empid").Value = txt_EmpID.Text
        End With

What I would like to happen is the first Column which is EMPID has to be populated depends on the value from txt_empID.text

I have added the

   .Rows(0).Cells("empid").Value = txt_EmpID.Text

But the below screenshot is what happens. I already have 2 rows of data loaded during run-time and if when I type data on the School column and it had lost its focus on the said column, the data I typed on the School column was replaced by the value of txt_EmpID.Text

Any suggestion how this happens and a way I can fix this?

Thanks.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>