Click here to Skip to main content
16,004,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've drawing CheckBox on my DataGridViewHeader but I don't know how to change for location.

This is picture of my DataGridView

http://imageshack.us/photo/my-images/856/datagrid.jpg/[^]

And this's my code

C#
ckBox = new CheckBox();
Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(1, -1,true);
<pre lang="c#">ckBox.Size = new Size(18, 18);
ckBox.Location = rect.Location;
ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
this.dataGridView1.Controls.Add(ckBox);


Please anyone guild me how to change for location or fixing CheckBox header at the middle of cell.

And last question: I want to resize the CheckBox on header

I've change this line

C#
ckBox.Size = new Size(18, 18);


to

C#
ckBox.Size = new Size(25, 25);


But size havn't changed. Why that??

Thank for helping
Posted
Updated 16-Feb-12 3:36am
v2

try some thing like that to change checkbox location, I am not sure it will work or not but try once

C#
ckBox.Location = new Point(rect.Location.X+1, rect.Location.Y+1);


If it works fine give me your feedback.

I have doubt while changing the size of CheckBox. As per my knowledge you cannot change size of CheckBox, I may be wrong. To verify the same add new CheckBox control on Form and try to change the size of same if works there it should work here as well.

If you have any other query revert back to me.
 
Share this answer
 
Comments
pongpanut 16-Feb-12 11:21am    
Thankyou for answer

i try with your code but it's not work but i've got idea from your answer


now i use this code
rect.Y = 4;
rect.X = rect.Location.X + (rect.Width / 3);

but it's still not center
you can use the html check box and add runat server tag , then use css to change the size of the check box.
 
Share this answer
 
Comments
pongpanut 16-Feb-12 11:22am    
i don't know how to do that can you guild me for more
Try Something like this:

CSS
<style type="text/css">

.mycheckBig input {width:25px; height:25px;}
.mycheckSmall input {width:10px; height:10px;}

</style>



<asp:checkbox id="CheckBoxBig" runat="server" checked="<%# Convert.ToBoolean(Eval(" active"))="" %&gt;"="" autopostback="False" cssclass="mycheckBig" xmlns:asp="#unknown">
 
Share this answer
 
Comments
pongpanut 16-Feb-12 12:48pm    
Thank you for answer

i've use Winform not asp.net

i'm so sorry i've explain on topic T T

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900