C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » DataGridView »

Disable CheckBoxes in a CheckBox Column of DataGridView Control


Posted Date: 21 May 2009    Resource Type: Code Snippets    Category: DataGridView
Author: Muralidharan RangarajuMember Level: Gold    
Rating: 1 out of 5Points: 10



In datagridview if we want to show some of the checkboxes in checkbox column as disabled one, below method can be used.
Logic:
Add an disable checkbox image to resources. In cell Painting event of Datagridview draw this disable checkbox image inside the cell.


private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//If first column is the checkbox column
if (e.ColumnIndex == 0)
{
//Get the image from resource
Image imgDisabled = (Image)Properties.Resources._disChecked;
for (int i = 0; i < e.RowIndex; i++)
{

try
{
//Clear the content in that cell
using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
e.Graphics.FillRectangle(backColorBrush, e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
}

////Draw 1 bottom line...
e.Graphics.DrawLine(Pens.DarkGray, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right, e.CellBounds.Bottom - 1);
//Draw right line...
e.Graphics.DrawLine(Pens.DarkGray, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom);
////Draw left line...
//Get the X and Y co-ordinates
int X = e.CellBounds.Left + ((e.CellBounds.Width - imgDisabled.Width) / 2);
int Y = e.CellBounds.Top + ((e.CellBounds.Height - imgDisabled.Height) / 2);
//Draw the image
e.Graphics.DrawImage(imgDisabled, X, Y);
e.Handled = true;
}
catch(Exception ex)
{

}
}
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Disabled Checkbox in Datagridview  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Verify any of the checkbox is selected in a checkbox column of Datagridview
Previous Resource: How to get the Values of Slected Cell Row DataGridview(Windows Appliction) using C#?
Return to Discussion Resource Index
Post New Resource
Category: DataGridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use