hi! I have datagrid view and a sub to clear my textboxes. The first row of record in my datagrid will be erased from the datagridview (but not in my table) whenever i clicked other rows of my datagrid. I know it has to do with my cleartextbox sub.
How do clear my textboxes with out erasing the records in my datagridview?
Here's my code.
Code:Private Sub frmSectionFile_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cnn.ConnectionString = "Data Source=.\sqlexpress;Initial Catalog=NDDU-IBED;Integrated Security=True" If cnn.State = ConnectionState.Closed Then cnn.Open() cmdSection = cnn.CreateCommand cmdSection.CommandText = "SELECT * FROM tblSection" daSection.SelectCommand = cmdSection daSection.Fill(dsSection, "tblSection") cnn.Close() 'bind datagrid view dtgSection.DataSource = dsSection.Tables("tblSection") 'format header display dtgSection.Columns("SectionID").HeaderText = "Section ID" dtgSection.Columns("SectionName").HeaderText = "Section Name" dtgSection.Columns("Yearlevel").HeaderText = "Year Level" 'bind textboxes txtSectionName.DataBindings.Add("Text", dsSection.Tables("tblSection"), "SectionName") txtYearLevel.DataBindings.Add("Text", dsSection.Tables("tblSection"), "YearLevel") txtSectionID.DataBindings.Add("Text", dsSection.Tables("tblsection"), "SectionID") ClearTextbox() Private Sub ClearTextbox() For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Text = String.Empty End If Next ctl




Reply With Quote