473,508 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Mar 21 '07 #1
6 19649

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP03.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?
Mar 22 '07 #2
The code below works in a simple form with a DataGridView and Button
dropped on it.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.DataGridView1.ColumnCount = 3
Me.DataGridView1.AllowUserToAddRows = False

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

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'either works
Me.DataGridView1.RowCount = 0
'Me.DataGridView1.Rows.Clear()
End Sub
==========================
Clay Burch
Syncfusion, Inc.

Mar 22 '07 #3
Me.DataGridView1.RowCount = 0
Me.DataGridView1.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" <cl***@syncfusion.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
The code below works in a simple form with a DataGridView and Button
dropped on it.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.DataGridView1.ColumnCount = 3
Me.DataGridView1.AllowUserToAddRows = False

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

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'either works
Me.DataGridView1.RowCount = 0
'Me.DataGridView1.Rows.Clear()
End Sub
==========================
Clay Burch
Syncfusion, Inc.

Mar 23 '07 #4

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Me.DataGridView1.RowCount = 0
Me.DataGridView1.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?
Mar 23 '07 #5
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" <pv****@newsgroups.nospamwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>
"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
> Me.DataGridView1.RowCount = 0
Me.DataGridView1.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?


Mar 23 '07 #6

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP02.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.dataGridView1.DataSource != null)
{
this.dataGridView1.DataSource = null;
}
else
{
this.dataGridView1.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.
Mar 23 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10220
by: dm1608 | last post by:
Hello, I have a DataGridView control in VB.NET 2005 that I would like to iterate thru row by row and parse out the individual columns into variables. Can someone provide me example code or direct...
2
32481
by: Chris Peeters | last post by:
Hi, I set up some columns in a DataGridView. I fill the DataGridView with some records by executing an sql-select statement .. so far so good Afterwards I clear the DataGridView using : ...
11
27276
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
1
1252
by: jjmurali | last post by:
hi guys i have one problem with datagridview.. i m displaying data in datagridview in c# application. i added one checkbox column to datagridview ..as well as i have one button(Select All),...
4
39738
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
how do you insert a new row to a databound datagridview? It won't allow this action.
4
7936
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
http://msdn2.microsoft.com/en-us/library/bt22et0f(VS.80).aspx Can anyone help me with how to use this? I am not sure whre to place the C# code they specify? THanks CM
1
6531
by: preeethi | last post by:
Hello, I'm designing a DataGridView that has a few combobox columns. As the user selects a value from a ComboBoxCell in a row. I want to populate another ComboBoxCell in the same row with the...
4
14761
by: rdubus | last post by:
After I have filled my datagridview I want to clear it up when the options for the query changes. I know how to clear the fields but I don't know how to clear the rows, so the datagridview appears...
4
20125
by: Michel Walsh | last post by:
Someone has an example, C#, about how to set the cell(int row, int col) as the current cell for a DataGridView. The example, in the help file, about DataGrid.CurrentCell Property (Set) ...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.