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# / April 2008

Tip: Looking for answers? Try searching our database.

Programmatically adding a column of Checkboxes to Gridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
d.s.stevenson@gmail.com - 29 Apr 2008 03:50 GMT
Hi,

Could someone please help me with sample code on how to
programmatically add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.
Saimvp - 29 Apr 2008 07:10 GMT
hi and hello good day.

you can try this codes:

//declare it to the top
DataGridViewCheckBoxColumn mygrid = new DataGridViewCheckBoxColumn();

       private void Form1_Load(object sender, EventArgs e)
       {
           mygrid.HeaderText = "Status";
           mygrid.Name = "status";
           grid.Columns.Insert(0, mygrid);
       }

       private void grid_CellMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
       {
           if (mygrid.ThreeState == false)
           {MessageBox.Show("check");}
           else
           {MessageBox.Show("uncheck");}
       }

I hope it can help u

Signature

To be Happy is To be Yourself

> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks in advance.
d.s.stevenson@gmail.com - 30 Apr 2008 02:14 GMT
Thanks for your help..  I get the following error when i try the code
you supplied.

cannot convert from 'System.Windows.Forms.DataGridViewCheckBoxColumn'
to System.Web.UI.WebControls.DataControlField'

code:

DataGridViewCheckBoxColumn mygrid = new DataGridViewCheckBoxColumn();
mygrid.HeaderText = "Status";
mygrid.Name = "status";
grdAdv.Columns.Insert(0, mygrid);    //Error produced on this line.

Any ideas?
Ignacio Machin ( .NET/ C# MVP ) - 29 Apr 2008 16:01 GMT
On Apr 28, 10:50 pm, d.s.steven...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks in advance.

Hi,

Take a look at ITemplate

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.