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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

dataGridView userDeletingRows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
noom - 24 Mar 2008 21:31 GMT
Hello
I`m trying to use userDeletingRows event but can`t deem to make it
work.
I tried :

this.dataGridView1.UserDeletedRow += new
DataGridViewRowCancelEventArgs

- but I get an error message on the arguments/
do I need to use a delegate (if so - which is it)?

can someone please post a full working example? (msdn didn`t help at
all...)

thnx
Marc Gravell - 24 Mar 2008 23:39 GMT
Yes you can only subscribe an delegate to an event.

UserDeletedRow is an event that accepts a DataGridViewRowEventHandler
UserDeletingRow is an event that accepts a
DataGridViewRowCancelEventHandler

Here's an example (using C# 3 syntax) that only allows delete on odd
rows; if the row index is even the delete is cancelled:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.ComponentModel;

class Foo
{
   public int Bar { get; set; }
   public int Bloop { get; set; }
}
static class Program
{
   [STAThread]
   static void Main()
   {
       Application.EnableVisualStyles();
       BindingList<Foo> foos = new BindingList<Foo>();
       for (int i = 0; i < 100; i++)
       {
           foos.Add(new Foo { Bar = i, Bloop = 200 - i });
       }
       DataGridView dgv = new DataGridView
       {
           Dock = DockStyle.Fill,
           DataSource = foos
       };
       dgv.UserDeletingRow += (sender, args) =>
       {
           args.Cancel = args.Row.Index % 2 == 0;
       };
       Application.Run(new Form
       {
           Controls = { dgv }
       });

   }
}

Rate this thread:







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.