Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / July 2007

Tip: Looking for answers? Try searching our database.

remove row in datagridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pascal Cloup - 26 Jul 2007 08:38 GMT
Hello,

How to remove a Row in a DataGridView?

My DataGridView is readonly and there is no binding (Cells are build
programmaticaly).
I tried the following

myDataGRidView.Rows.RemoveAt( rowIndex ) and myDataGRidView.Rows.Remove(
row ) but an exception is always generated: "Impossible de supprimer la
nouvelle ligne non validée" , HResult:0x80131509.

Someone can help?

thanks in advance

Pascal
Morten Wennevik [C# MVP] - 26 Jul 2007 09:35 GMT
> Hello,
>
[quoted text clipped - 13 lines]
>
> Pascal

Hi Pascal,

Unless you seek help from people understanding French, please translate the error message to English.

Anyhow,  DataGridView.Rows.RemoveAt(index) should work just fine.  How do you create the DataGridView/Rows?

The code below works fine in VS 2005 and Orcas

        DataGridView dataGridView1 = new DataGridView();
        protected override void OnLoad(EventArgs e)
        {
            this.Controls.Add(dataGridView1);
            dataGridView1.Columns.Add("Column", "Column");
            dataGridView1.Rows.Add(3);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.RemoveAt(0);
        }

Signature

Happy coding!
Morten Wennevik [C# MVP]

Pascal Cloup - 26 Jul 2007 14:29 GMT
Hi Morten,

the error message translation gives: "Impossible to suppress the new not
validated line", well

I found the problem. In fact, Remove or RemoveAt doesn't work with the last
row of a DataGridView!
something like :
myDataGRidView.Rows.RemoveAt( myDataGRidView.Rows.Count - 1);
generated an exception!

best regards
Pascal

>> Hello,
>>
[quoted text clipped - 36 lines]
>             dataGridView1.Rows.RemoveAt(0);
>         }
ClayB - 28 Jul 2007 09:54 GMT
If you do not want to see the AddNew row (the last row which is
initially empty), you can set

        this.dataGridView1.AllowUserToAddRows = false;

==========
Clay Burch
Syncfusion, Inc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.