private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1) //checkbox col
{
rightZeroCountsc = GetRightZeroCounts(CommonFunc.GetDbInt(dataGridView1.Rows[e.RowIndex].Cells[0].Value), out firstNotZeroNumc);
if (rightZeroCountsc == 2) e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
else if (rightZeroCountsc == 3) e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
else
{
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
}
}
上面的是控制checkbox列位置的式样,但是选中某个checkbox后还是会跳到中间显示,如何解决这个问题?
{
if (e.ColumnIndex == 1) //checkbox col
{
rightZeroCountsc = GetRightZeroCounts(CommonFunc.GetDbInt(dataGridView1.Rows[e.RowIndex].Cells[0].Value), out firstNotZeroNumc);
if (rightZeroCountsc == 2) e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
else if (rightZeroCountsc == 3) e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
else
{
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
}
}
上面的是控制checkbox列位置的式样,但是选中某个checkbox后还是会跳到中间显示,如何解决这个问题?
解决方案 »
- WinCE 代码添加回车
- 可作为DLL加载的exe程序怎么变得?
- LINQ to SQL和LINQ to Entities还有Entity Framework貌似都是重复的?
- textbox获取当前输入的值
- 如何将一个16进制的字符串转换成整数?
- 请问怎样才能重新设定WinForm的dataGrid顶部标题?
- 用System.Diagnostics.Process.Start("c:\\test.xls")打开Excel文档的怪问题
- 【讨论】c#里面能不能去截取windows应用程序的某些事件
- 在C#中,如何获得图像的各个信息???
- 简单问题!请大家帮忙解答!
- 怎样用C#实现 在给定的数字中随机生成7个数字?
- 新手问题 C# 上传文件传输问题
datagridview1.columns["col1"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
if (e.ColumnIndex == 0)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.Alignment = DataGridViewContentAlignment.TopLeft; //用这个而不是下面那行。
}
//e.CellStyle.Alignment = DataGridViewContentAlignment.BottomRight;