- VBForums
- Visual Basic
- Visual Basic .NET
- How to clear a DataGridView?
- If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Results 1 to 22 of 22 Thread: How to clear a DataGridView? - Apr 9th, 2007, 11:06 AM #1 dogboydelta
- View Profile
- View Forum Posts
Thread Starter Fanatic Member Join Date Jun 2005 Posts 625 How to clear a DataGridView? How do I clear a DataGridView? Basically I want the user to be able to click the button again that fills it and it will erase everything and refresh the data. Reply With Quote - Apr 9th, 2007, 11:21 AM #2 Dean_Reedy
- View Profile
- View Forum Posts
Lively Member Join Date May 2000 Location Iowa USA Posts 118 Re: How to clear a DataGridView? Try: myGrid.Rows.Clear Reply With Quote - Apr 9th, 2007, 11:33 AM #3 dogboydelta
- View Profile
- View Forum Posts
Thread Starter Fanatic Member Join Date Jun 2005 Posts 625 Re: How to clear a DataGridView? Got an exception: Cannot clear this list .. ? Reply With Quote - Apr 9th, 2007, 11:38 AM #4 GaryMazzone
- View Profile
- View Forum Posts
A SQL Server fool Join Date Aug 2005 Location Dover,NH Posts 7,493 Re: How to clear a DataGridView? Try DataGridView.DataSource = Nothing Sometimes the Programmer Sometimes the DBA Mazz1 Reply With Quote - Apr 9th, 2007, 11:44 AM #5 dogboydelta
- View Profile
- View Forum Posts
Thread Starter Fanatic Member Join Date Jun 2005 Posts 625 Re: How to clear a DataGridView? Didn't work. Reply With Quote - Apr 9th, 2007, 11:52 AM #6 GaryMazzone
- View Profile
- View Forum Posts
A SQL Server fool Join Date Aug 2005 Location Dover,NH Posts 7,493 Re: How to clear a DataGridView? Was there an error? What was it if so. Sometimes the Programmer Sometimes the DBA Mazz1 Reply With Quote - Apr 9th, 2007, 12:05 PM #7 dogboydelta
- View Profile
- View Forum Posts
Thread Starter Fanatic Member Join Date Jun 2005 Posts 625 Re: How to clear a DataGridView? no error, just didn't clear anything. Reply With Quote - Apr 9th, 2007, 12:13 PM #8 GaryMazzone
- View Profile
- View Forum Posts
A SQL Server fool Join Date Aug 2005 Location Dover,NH Posts 7,493 Re: How to clear a DataGridView? This is what I do to clear and set a DataGridView with data: vb Code: - Public Sub getComments()
- Me.dgComments.DataSource = Nothing
- Dim oDS As System.Data.DataSet
- Dim strSQL As String = String.Empty
- strSQL = "Select a.CommentPK,a.IssuePK,a.ContactPK,b.FirstName & "" "" & b.LastName AS [Comment By],a.CommentDate As [Date of Comment],a.Comments "
- strSQL &= "From CommentTable a, Contacts b "
- strSQL &= "Where a.ContactPK = b.ContactPK And "
- strSQL &= "a.IssuePK = " & intIssuePK.ToString() & " "
- strSQL &= "Order By CommentDate Desc"
- da = New clsDataAccess
- oDS = da.Return_DataSet(strSQL)
- If Not oDS Is Nothing Then
- Me.dgComments.DataSource = oDS.Tables(0)
- oDS.Dispose()
- da.Dispose()
- Me.dgComments.Columns(0).Visible = False
- Me.dgComments.Columns(1).Visible = False
- Me.dgComments.Columns(2).Visible = False
- Me.dgComments.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
- Me.dgComments.Columns(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
- Me.dgComments.Columns(5).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
- End If
- If mdlGeneral.errMessage.intErrNum <> 0 Then
- MessageBox.Show(mdlGeneral.errMessage.strMess.Trim(), "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End If
This is called from and other sub Sometimes the Programmer Sometimes the DBA Mazz1 Reply With Quote - Apr 9th, 2007, 03:06 PM #9 Dean_Reedy
- View Profile
- View Forum Posts
Lively Member Join Date May 2000 Location Iowa USA Posts 118 Re: How to clear a DataGridView? Since you are using a bound grid, have you tried to call your loading function twice and verified that the data is not doubling? Since it is bound, loading twice ought to not duplicate the data. Reply With Quote - Apr 9th, 2007, 07:51 PM #10 jmcilhinney
- View Profile
- View Forum Posts
- Visit Homepage
Super Moderator Join Date May 2005 Location Sydney, Australia Posts 110,796 Re: How to clear a DataGridView? Some people are so forthcoming with information. Is this grid bound to a DataSource or not? If it is then what is it bound to, a DataTable or something else? Why is my data not saved to my database? | MSDN Data Walkthroughs VBForums Database Development FAQ My CodeBank Submissions: VB | C# My Blog: Data Among Multiple Forms (3 parts) Beginner Tutorials: VB | C# | SQL Reply With Quote - Apr 9th, 2007, 10:35 PM #11 steve_rm
- View Profile
- View Forum Posts
Frenzied Member Join Date Dec 2001 Posts 1,331 Re: How to clear a DataGridView? Hello, I think clearing the data source and not the datagrid would be a better idea. Steve steve Reply With Quote - Nov 5th, 2008, 11:35 PM #12 praveenbhosage
- View Profile
- View Forum Posts
New Member Join Date Nov 2008 Posts 1 Re: How to clear a DataGridView? BindingSource.Datasource=Empty Dataset; Datagridview.Datasource=BindingSource; Cheers, The Wolverine Reply With Quote - Oct 6th, 2011, 01:06 PM #13 A_hemati
- View Profile
- View Forum Posts
New Member Join Date Oct 2011 Posts 1 Re: How to clear a DataGridView? Just clear your dataset like this: dataset1.Clear() Reply With Quote - Oct 24th, 2011, 06:09 PM #14 Svilen Zhelev
- View Profile
- View Forum Posts
New Member Join Date Oct 2011 Posts 1 Re: How to clear a DataGridView? Just declare Dataset in the click event of the button. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ds1 As New DataSet ......... Reply With Quote - Oct 25th, 2011, 06:24 AM #15 .paul.
- View Profile
- View Forum Posts
- Visit Homepage
eXtreme Programmer Join Date May 2007 Location Chelmsford UK Posts 25,755 Re: How to clear a DataGridView? this thread is 4.5 years old. it might be resolved by now - Coding Examples: My Web Site | CodeBank Submissions
- Features: Sorting Techniques | DataGridView Printing | Average Strategies - Plugin Version
- Online Games: hangMan | masterMind | sudoku | crack the lock | numbers game | Fit Words | Fit Numbers | Crossword Hangman
- Compiled Games: Puzzle Games
Reply With Quote - Oct 25th, 2011, 06:35 AM #16 Joshlad
- View Profile
- View Forum Posts
Addicted Member Join Date May 2011 Location England Posts 160 Re: How to clear a DataGridView? hahaha Originally Posted by Shaggy Hiker EDIT: Wow, I think I need to refresh my browser faster. You had it solved before I even started writing. May not be able to provide code, but i sure can provide the logic AutoTyper Moves Mouse Cursor to Screen Position All my Projects contain flashy scrolling text Reply With Quote - Feb 16th, 2012, 08:21 PM #17 abidquraishi
- View Profile
- View Forum Posts
New Member Join Date Feb 2012 Posts 1 Re: How to clear a DataGridView? Originally Posted by dogboydelta How do I clear a DataGridView? Basically I want the user to be able to click the button again that fills it and it will erase everything and refresh the data. When you want to clear DataGridView rows and trying to show another records from the record selection query; Simply write the following code: First Clear the DataSet and then select that cleared dataset for your query ds.Clear() DataGridView.DataSource = ds Reply With Quote - Mar 4th, 2012, 12:52 PM #18 Manolis
- View Profile
- View Forum Posts
New Member Join Date Mar 2012 Posts 1 Re: How to clear a DataGridView? Usually setting Datasource to nothing is enough. You may use all three statements as well. Datagridview1.Datasource = nothing Datagridview1.Rows.clear Datagridview1.Columns.clear Manolis Reply With Quote - Jan 17th, 2017, 08:22 AM #19 Trubadur
- View Profile
- View Forum Posts
New Member Join Date Jan 2017 Posts 3 Re: How to clear a DataGridView? My vb does not accept Datagridview1.Rows.clear... so this is one solution: Datagridview1.Datasource = nothing datagridview1.refresh Reply With Quote - Mar 21st, 2020, 01:37 PM #20 LordAlex
- View Profile
- View Forum Posts
New Member Join Date Mar 2020 Posts 1 Re: How to clear a DataGridView? I know it might be a bit long-winded, but maybe you could try something along the lines of: Grid.Rows(x).Cells(y).Value = "" and repeat for all the rows and cells Just an idea Reply With Quote - Mar 21st, 2020, 02:09 PM #21 wes4dbt
- View Profile
- View Forum Posts
PowerPoster Join Date Sep 2005 Location Modesto, Ca. Posts 5,279 Re: How to clear a DataGridView? This question is over 3yrs old??? Reply With Quote - Mar 22nd, 2020, 10:24 AM #22 jmcilhinney
- View Profile
- View Forum Posts
- Visit Homepage
Super Moderator Join Date May 2005 Location Sydney, Australia Posts 110,796 Re: How to clear a DataGridView? Originally Posted by wes4dbt This question is over 3yrs old??? The thread is 13 years old. It has been resurrected five times by people making their first post. Apparently, this thread is a magnet for would-be heroes who probably haven't actually read any of the previous posts. Why is my data not saved to my database? | MSDN Data Walkthroughs VBForums Database Development FAQ My CodeBank Submissions: VB | C# My Blog: Data Among Multiple Forms (3 parts) Beginner Tutorials: VB | C# | SQL Reply With Quote Quick Navigation Visual Basic .NET Top - Site Areas
- Settings
- Private Messages
- Subscriptions
- Who's Online
- Search Forums
- Forums Home
- Forums
- Visual Basic
- Visual Basic .NET
- CodeBank - VB.net
- Visual Basic 6 and Earlier
- CodeBank - Visual Basic 6 and earlier
- TwinBASIC
- CodeBank - TwinBASIC
- Universal Windows Platform and Modern Windows Experience
- Xamarin
- Mobile Development
- ASP, VB Script
- Office Development
- Database Development
- Reporting
- API
- Games and Graphics Programming
- Game Demos
- COM and ActiveX
- Network Programming
- Visual Basic FAQs
- Slow Chat with the Microsoft Visual Basic team
- .NET and More
- ASP.NET And ASP.NET Core
- Visual Basic .NET
- MVC .Net
- C#
- Microsoft Azure and Cloud Dev
- WPF, WCF, WF
- .NET Architecture and Design
- Silverlight
- General
- General Developer Forum
- IoT, IoE, and Maker Forum
- Testers and Testing
- Application Testing
- Application Deployment
- Linux Development
- General PC
- VBForums Coding Contests
- Contest Entries
- Code It Better
- Maths Forum
- Other Languages
- Other BASIC
- C and C++
- Java
- PHP
- XML, HTML, Javascript, Web and CSS
- jQuery
- Assembly
- Other Programming Languages
- VBForums CodeBank
- CodeBank - Visual Basic .NET
- CodeBank - Visual Basic 6 and earlier
- CodeBank - ASP / ASP.NET / Blazor / MVC / Web API
- CodeBank - C#
- CodeBank - C++
- CodeBank - Java / J#
- CodeBank - PHP
- Codebank - Game Programming
- Codebank - Mobile Development
- CodeBank - JavaScript
- Codebank - Cascading Style Sheets (CSS)
- CodeBank - Other
- VBForums UtilityBank
- UtilityBank - Utilities
- UtilityBank - IDE Add-Ins
- UtilityBank - Components
- UtilityBank - Tutorials
- UtilityBank - Other
- Projects
- Project Requests
- Project Communication Area
- Jobs
- Just VB Jobs
- Open Positions (Jobs)
- Looking for Work
- Community
- Forum Feedback
- General Discussion / Chit Chat
- World Events
- Forum Test Area
« Previous Thread | Next Thread » - VBForums
- Visual Basic
- Visual Basic .NET
- How to clear a DataGridView?
Posting Permissions - You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules | Click Here to Expand Forum to Full Width |