Cannot clear all rows in datagridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Nguyen

    Cannot clear all rows in datagridview

    I tried almost everything
    ..Rows.clear()
    ..rowcount = 0
    and the rows in a datagridview still not cleared

    I populated the Datagridview manually using Row.Add

    Any help is greatly appreciated

    Bill


  • pvdg42

    #2
    Re: Cannot clear all rows in datagridview


    "Bill Nguyen" <billn_nospam_p lease@jaco.comw rote in message
    news:%23pH7ivAb HHA.4544@TK2MSF TNGP03.phx.gbl. ..
    >I tried almost everything
    .Rows.clear()
    .rowcount = 0
    and the rows in a datagridview still not cleared
    >
    I populated the Datagridview manually using Row.Add
    >
    Any help is greatly appreciated
    >
    Bill
    >
    How do you know that the clear() method is not working?


    Comment

    • ClayB

      #3
      Re: Cannot clear all rows in datagridview

      The code below works in a simple form with a DataGridView and Button
      dropped on it.

      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      Me.DataGridView 1.ColumnCount = 3
      Me.DataGridView 1.AllowUserToAd dRows = False

      Me.DataGridView 1.Rows.Add(New String() {"abc", "efg", "hij"})
      Me.DataGridView 1.Rows.Add(New String() {"111", "efg", "hij"})
      Me.DataGridView 1.Rows.Add(New String() {"222", "efg", "hij"})

      End Sub

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
      As System.EventArg s) Handles Button1.Click
      'either works
      Me.DataGridView 1.RowCount = 0
      'Me.DataGridVie w1.Rows.Clear()
      End Sub
      =============== ===========
      Clay Burch
      Syncfusion, Inc.

      Comment

      • Bill Nguyen

        #4
        Re: Cannot clear all rows in datagridview

        Me.DataGridView 1.RowCount = 0
        Me.DataGridView 1.Rows.Clear()

        It didn't work on mine.
        Is it a problem with version/SP update?
        I'm usign VS 2005. Info as below

        Thanks
        Bill


        Microsoft Visual Studio 2005
        Version 8.0.50727.42 (RTM.050727-4200)
        Microsoft .NET Framework
        Version 2.0.50727

        Installed Edition: Professional

        Microsoft Visual Basic 2005 77626-009-0000007-41468
        Microsoft Visual Basic 2005

        Microsoft Visual C# 2005 77626-009-0000007-41468
        Microsoft Visual C# 2005

        Microsoft Visual C++ 2005 77626-009-0000007-41468
        Microsoft Visual C++ 2005

        Microsoft Visual J# 2005 77626-009-0000007-41468
        Microsoft Visual J# 2005

        Microsoft Visual Web Developer 2005 77626-009-0000007-41468
        Microsoft Visual Web Developer 2005

        Crystal Reports AAC60-G0CSA4B-V7000AY
        Crystal Reports for Visual Studio 2005


        Security Update for Microsoft Visual Studio 2005 Professional Edition - ENU
        (KB925674)
        This Security Update is for Microsoft Visual Studio 2005 Professional
        Edition - ENU. \n
        If you later install a more recent service pack, this Security Update will
        be uninstalled automatically. \n
        For more information, visit http://support.microsoft.com/kb/925674

        SQL Server Analysis Services
        Microsoft SQL Server Analysis Services Designer
        Version 9.00.3042.00

        SQL Server Integration Services
        Microsoft SQL Server Integration Services Designer
        Version 9.00.2047.00

        SQL Server Reporting Services
        Microsoft SQL Server Reporting Services Designers
        Version 9.00.2047.00

        "ClayB" <clayb@syncfusi on.comwrote in message
        news:1174553404 .996886.281970@ y66g2000hsf.goo glegroups.com.. .
        The code below works in a simple form with a DataGridView and Button
        dropped on it.
        >
        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        Me.DataGridView 1.ColumnCount = 3
        Me.DataGridView 1.AllowUserToAd dRows = False
        >
        Me.DataGridView 1.Rows.Add(New String() {"abc", "efg", "hij"})
        Me.DataGridView 1.Rows.Add(New String() {"111", "efg", "hij"})
        Me.DataGridView 1.Rows.Add(New String() {"222", "efg", "hij"})
        >
        End Sub
        >
        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
        As System.EventArg s) Handles Button1.Click
        'either works
        Me.DataGridView 1.RowCount = 0
        'Me.DataGridVie w1.Rows.Clear()
        End Sub
        =============== ===========
        Clay Burch
        Syncfusion, Inc.
        >

        Comment

        • pvdg42

          #5
          Re: Cannot clear all rows in datagridview


          "Bill Nguyen" <billn_nospam_p lease@jaco.comw rote in message
          news:%23Go$jtXb HHA.4140@TK2MSF TNGP06.phx.gbl. ..
          Me.DataGridView 1.RowCount = 0
          Me.DataGridView 1.Rows.Clear()
          >
          It didn't work on mine.
          Is it a problem with version/SP update?
          I'm usign VS 2005. Info as below
          >
          Thanks
          Bill
          >
          <snip>

          I'll try again. How, exactly, do you know that Clear() is not working?
          Have you added code to your application to check the remaining contents of
          the DataTable within your DataGridView during the same run, or are you
          checking your DataSource while in design mode?


          Comment

          • Bill Nguyen

            #6
            Re: Cannot clear all rows in datagridview

            I'm not going that far.
            The Datagridview was still showing data. I want it to be cleared in my view.
            If it cleared but I can still see all the rows and columns on the screen, I
            would say that it's not working!

            Thanks

            Bill

            "pvdg42" <pvdg42@newsgro ups.nospamwrote in message
            news:eaIQ8OYbHH A.2088@TK2MSFTN GP04.phx.gbl...
            >
            "Bill Nguyen" <billn_nospam_p lease@jaco.comw rote in message
            news:%23Go$jtXb HHA.4140@TK2MSF TNGP06.phx.gbl. ..
            > Me.DataGridView 1.RowCount = 0
            >Me.DataGridVie w1.Rows.Clear()
            >>
            >It didn't work on mine.
            >Is it a problem with version/SP update?
            >I'm usign VS 2005. Info as below
            >>
            >Thanks
            >Bill
            >>
            <snip>
            >
            I'll try again. How, exactly, do you know that Clear() is not working?
            Have you added code to your application to check the remaining contents of
            the DataTable within your DataGridView during the same run, or are you
            checking your DataSource while in design mode?
            >
            >

            Comment

            • pvdg42

              #7
              Re: Cannot clear all rows in datagridview


              "Bill Nguyen" <billn_nospam_p lease@jaco.comw rote in message
              news:%23FNNvqYb HHA.2448@TK2MSF TNGP02.phx.gbl. ..
              I'm not going that far.
              The Datagridview was still showing data. I want it to be cleared in my
              view. If it cleared but I can still see all the rows and columns on the
              screen, I would say that it's not working!
              >
              Thanks
              >
              Bill
              >
              I would agree :)

              Here's an article written on the subject that may be useful:

              <quote>

              I guess it depends on how you're populating the DataGridView. If it's bound
              to a data source then I would remove the binding; otherwise, if the rows
              were added manually then I would just clear the rows collection.

              if (this.dataGridV iew1.DataSource != null)
              {
              this.dataGridVi ew1.DataSource = null;


              }


              else
              {
              this.dataGridVi ew1.Rows.Clear( );


              }


              Does that work in your situation?

              --
              Tim Wilson
              ..NET Compact Framework MVP


              </quote>

              I realize the code is C#, but the translation should pose no problems. Works
              for me.


              Comment

              Working...