Clearing Datagridview when combobox item is changed [modified]
-
hi guys, im trying to develop an application in which i used a combobox and datagridview in visual basic. I want to clear old content of datagridview before i populate with new ones when combobox.selecteditem changes.i add data to datagridview manually(programmatically). I don't use datagridview datasource property. when i tried to use datagridview1.rows.clear or dataset.tables.clear, it doesnot clear. rather it duplicates data by adding old and new data to datagridview.i searched on web but i couldn't find an answer, any help? thank you so much in advance for any help. My sample code looks like the following DataGridView1.Rows.Clear() c.da = New SqlDataAdapter(userdata,userconn) c.da.Fill(c.ds, "usertable") 'c.ds.GetChanges() c.custView = New DataView(c.ds.Tables("usertable"), "", "studid", DataViewRowState.CurrentRow For c.rowIndex = 0 To c.ds.Tables("usertable").Rows.Count - 1 Dim row0 As String() = {c.custView(c.rowIndex)("column1").ToString, c.custView(c.rowIndex)("column2").ToString, c.custView(c.rowIndex)("colum3").ToString, c.custView(c.rowIndex)("colum4").ToString} With Me.DataGridView1.Rows .Add(row0) End With Next
modified on Thursday, August 6, 2009 10:25 AM
-
hi guys, im trying to develop an application in which i used a combobox and datagridview in visual basic. I want to clear old content of datagridview before i populate with new ones when combobox.selecteditem changes.i add data to datagridview manually(programmatically). I don't use datagridview datasource property. when i tried to use datagridview1.rows.clear or dataset.tables.clear, it doesnot clear. rather it duplicates data by adding old and new data to datagridview.i searched on web but i couldn't find an answer, any help? thank you so much in advance for any help. My sample code looks like the following DataGridView1.Rows.Clear() c.da = New SqlDataAdapter(userdata,userconn) c.da.Fill(c.ds, "usertable") 'c.ds.GetChanges() c.custView = New DataView(c.ds.Tables("usertable"), "", "studid", DataViewRowState.CurrentRow For c.rowIndex = 0 To c.ds.Tables("usertable").Rows.Count - 1 Dim row0 As String() = {c.custView(c.rowIndex)("column1").ToString, c.custView(c.rowIndex)("column2").ToString, c.custView(c.rowIndex)("colum3").ToString, c.custView(c.rowIndex)("colum4").ToString} With Me.DataGridView1.Rows .Add(row0) End With Next
modified on Thursday, August 6, 2009 10:25 AM
Set the DataSource of the DataGridView to null. You should update the Filter property of the BindingSource in the SelectedIndexChanged event of the ComboBox if you you have a single datasource and filtering out the records to display on the basis of the user selection.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
Set the DataSource of the DataGridView to null. You should update the Filter property of the BindingSource in the SelectedIndexChanged event of the ComboBox if you you have a single datasource and filtering out the records to display on the basis of the user selection.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
hi d@nish i am not setting the data source of datagridview using the datasource property, rather i am setting manually(programmatically), so i can't use bindingsource control. sorry may be 'cause i am stupid.
-
Try Remove method of the datagridview row.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD