Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Clearing Datagridview when combobox item is changed [modified]

Clearing Datagridview when combobox item is changed [modified]

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dambod
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • D Dambod

      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

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • D dan sh

        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

        D Offline
        D Offline
        Dambod
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • D Dambod

          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.

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Try Remove method of the datagridview row.

          It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

          D 1 Reply Last reply
          0
          • D dan sh

            Try Remove method of the datagridview row.

            It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

            D Offline
            D Offline
            Dambod
            wrote on last edited by
            #5

            thank u guys, i got the solution to my problems

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups