DataGridView合并单元格后如何使文字居中显示,如果文本长度超出单元格长度,隐藏超出部分
解决方案 »
- 请问,这个批量查询的刷新行数为什么没对?
- C#使用权举时定义两个类出现问题(上下文不存在名称:XX)
- 如何判断一个路径是否存在,不存在则创建
- 有没有人做过语言xml文件
- c#winform连接access数据库藏access 数据库保存在我当前项目文件夹DataSourece下 叫做Diary.mdb相对路径该怎么写呀我怎么也写不了
- CommonDialog如何设置初始大小?
- 关于保存Text类型字段和Ntext类型字段的问题
- c# 读取USB Mass Storage Device
- 怎样将Checkboxlist中显示的项在初始情况下都设为没被选中?
- XML节点值获取
- 一个类必须要独占一个文件吗?还是可以将多个类放在一个文件中?
- 析造函数,为何用断点和跟踪都看不到呢?如何查看析构函数的执行呢?
DefaultCellStyle
#region 重绘单元格
/// <summary>
/// 重绘单元格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridViewBom_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex > -1)
{
if (this.dataGridViewBom.Rows[e.RowIndex].DefaultCellStyle.BackColor == Color.Gray && this.dataGridViewBom.Rows[e.RowIndex].ReadOnly == true)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (Brush gridBrush = new SolidBrush(this.dataGridViewBom.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
//擦出单元格背景
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
if (e.ColumnIndex == this.dataGridViewBom.ColumnCount - 1)
{
//画右侧线
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom);
}
double rowLen = this.dataGridViewBom.Columns.GetColumnsWidth(DataGridViewElementStates.Displayed);
Graphics g = this.CreateGraphics();
//if (e.Value != null)
//{
//}
string s = "";
for (int i = 0; i < equipNameList.Count; i++)
{
if (e.RowIndex == Convert.ToInt32(equipNameList[i][1]))
{
s = equipNameList[i][0];
break;
}
}
try
{
e.Graphics.DrawString(this.dataGridViewBom.Rows[e.RowIndex].Cells[0].Value.ToString(), e.CellStyle.Font, Brushes.Red, (float)rowLen / 2 - 20, e.CellBounds.Y + 5, StringFormat.GenericDefault);
}
catch
{
e.Graphics.DrawString(s, e.CellStyle.Font, Brushes.Red, (float)rowLen / 2 - 20, e.CellBounds.Y + 5, StringFormat.GenericDefault);
}
//else
//{
// e.Graphics.DrawString("", e.CellStyle.Font, Brushes.Red, (float)rowLen / 2 - 20, e.CellBounds.Y + 5, StringFormat.GenericDefault);
//}
//下边缘线
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
e.Handled = true;
}
}
ed.UpdateScreen();
}
}
}
#endregion
.cut_div{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}<div class="cut_div" title='<%#((DataRowView)Container.DataItem)[""]%>'></div>