如何根据从数据库中检索的记录动态合并C#中的datagridview行 [英] How to merge rows of datagridview in C# dynamically based on the records retrieved from database
本文介绍了如何根据从数据库中检索的记录动态合并C#中的datagridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请根据从数据库中检索到的记录,帮助如何在c#中动态合并datagridview中的行。
我尝试过:
这是我尝试过的但是徒劳无功。
Please help how to merge rows in datagridview in c# dynamically based on the records retrieved from database.
What I have tried:
This is what i have tried but in vain.
private void MergeCellsInColumn(int col, int row1, int row2)
{
Graphics g = dgv_loadsurvey.CreateGraphics();
Pen p = new Pen(dgv_loadsurvey.GridColor);
System.Drawing.Rectangle r1 = dgv_loadsurvey.GetCellDisplayRectangle(col, row1, true);
System.Drawing.Rectangle r2 = dgv_loadsurvey.GetCellDisplayRectangle(col, row2, true);
int recHeight = 0;
string recValue = string.Empty;
for (int i = row1; i <= row2; i++)
{
recHeight += dgv_loadsurvey.GetCellDisplayRectangle(col, i, true).Height;
if (dgv_loadsurvey[col, i].Value != null)
recValue += dgv_loadsurvey[col, i].Value.ToString() + " ";
}
System.Drawing.Rectangle newCell = new System.Drawing.Rectangle(r1.X, r1.Y, r1.Width, recHeight);
g.FillRectangle(new SolidBrush(dgv_loadsurvey.DefaultCellStyle.BackColor), newCell);
g.DrawRectangle(p, newCell);
g.DrawString(recValue, dgv_loadsurvey.DefaultCellStyle.Font, new SolidBrush(dgv_loadsurvey.DefaultCellStyle.ForeColor), newCell.X + 3, newCell.Y + 3);
}
推荐答案
你好
怎么样
hello
what about
way to directly access and manipulate a DataGridCell in a specified DataGrid? C# Visual Studio 2015 Community
这篇关于如何根据从数据库中检索的记录动态合并C#中的datagridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文