当用户在运行时键入内容时,是否有可能扩大datagridview单元格的高度. [英] Is it possible to expand the datagridview cell height as the user is typing on run time.

查看:125
本文介绍了当用户在运行时键入内容时,是否有可能扩大datagridview单元格的高度.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在用户在运行时键入时扩展datagridview单元格的高度.

Is it possible to expand the datagridview cell height as the user is typing on run time.

推荐答案

首先,您必须设置特定的单元格-WrapMode属性应为是的.
然后可以将Paint函数用于datagridview.
无论您在单元格中键入什么,此功能都会自动增加行高

这是示例绘画功能之一.
First you have to set particular cell - WrapMode property should be true.
Then you can use Paint function for datagridview.
this function automatically increased row height whatever you typed in cell

This is one of sample paint function.
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
try
{
int mergeindex = ColumnIndex - m_nLeftColumn;
int i;
int nWidth;
int nWidthLeft;
string strText;
Pen pen = new Pen(Brushes.Black);
// Draw the background
graphics.FillRectangle(new SolidBrush(SystemColors.Control), cellBounds);
// Draw the separator for rows
graphics.DrawLine(new Pen(new SolidBrush(SystemColors.ControlDark)), cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);
// Draw the right vertical line for the cell
if (ColumnIndex == m_nRightColumn)
graphics.DrawLine(new Pen(new SolidBrush(SystemColors.ControlDark)), cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom);
// Draw the text
RectangleF rectDest = RectangleF.Empty;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.Trimming = StringTrimming.EllipsisCharacter;
// Determine the total width of the merged cell
nWidth = 0;
for (i = m_nLeftColumn; i <= m_nRightColumn; i++)
nWidth += this.OwningRow.Cells[i].Size.Width;
// Determine the width before the current cell.
nWidthLeft = 0;
for (i = m_nLeftColumn; i < ColumnIndex; i++)
nWidthLeft += this.OwningRow.Cells[i].Size.Width;
// Retrieve the text to be displayed
strText = this.OwningRow.Cells[m_nLeftColumn].Value.ToString();
rectDest = new RectangleF(cellBounds.Left - nWidthLeft, cellBounds.Top, nWidth, cellBounds.Height);
graphics.DrawString(strText, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, rectDest, sf);
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
}


这篇关于当用户在运行时键入内容时,是否有可能扩大datagridview单元格的高度.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆