WinForm DataGridView控件如何做到Excel这种筛选? [图] 为每一列group后的值动态生成下拉列表框 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我提供个思路,也就是DataGridView空间中加了list 的功能自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计 "每一列group后的值"? 不明白这个,能否给个小小的示例代码段? http://msdn.microsoft.com/zh-cn/library/aa480727(en-us).aspx谁能把这个翻译, 贴个示例出来? 发段代码上来 希望对你有帮助!!/// <summary> /// 触发CellPainting事件 /// </summary> /// <param name="e"></param> protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { #region 画列头下拉框 if (isColumnHeaderFilter && e.RowIndex == -1 && e.ColumnIndex > -1) { string columnName = Columns[e.ColumnIndex].Name; bool find = false; foreach (string name in filterColumnNames) { if (string.Compare(name, columnName, true) == 0) { find = true; break; } } if (find) { e.PaintBackground(e.ClipBounds, false); e.PaintContent(e.ClipBounds); e.Paint(e.ClipBounds, DataGridViewPaintParts.SelectionBackground | DataGridViewPaintParts.Focus | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentBackground); // 画按钮 Rectangle rect = GetColumnHeaderDropDownBounds(e.CellBounds); e.Graphics.FillRectangle(SystemBrushes.ButtonFace, rect); Point pLT = rect.Location; Point pRT = new Point(rect.Right, rect.Top); Point pLB = new Point(rect.Left, rect.Bottom); Point pRB = new Point(rect.Right, rect.Bottom); e.Graphics.DrawLine(SystemPens.ButtonHighlight, pLT, pRT); e.Graphics.DrawLine(SystemPens.ButtonHighlight, pLT, pLB); e.Graphics.DrawLine(SystemPens.ButtonShadow, pRT, pRB); e.Graphics.DrawLine(SystemPens.ButtonShadow, pLB, pRB); // 画三角形 Point p31 = new Point(pLT.X + (pRT.X - pLT.X) / 4, pLT.Y + (pLB.Y - pLT.Y) / 4); Point p32 = new Point(pRT.X - (pRT.X - pLT.X) / 4, pLT.Y + (pLB.Y - pLT.Y) / 4); Point p33 = new Point(pLT.X + (pRT.X - pLT.X) / 2, pLB.Y - (pLB.Y - pLT.Y) / 4); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int[] columnList = new int[columnHeaderFilter.Keys.Count]; columnHeaderFilter.Keys.CopyTo(columnList, 0); if (Array.IndexOf(columnList, e.ColumnIndex) == -1) { e.Graphics.FillPolygon(SystemBrushes.ControlText, new Point[] { p31, p32, p33, p31 }); } else { e.Graphics.FillPolygon(SystemBrushes.ControlLightLight, new Point[] { p31, p32, p33, p31 }); } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; e.Handled = true; } } #endregion base.OnCellPainting(e); } DataGridView空间中加了list 的功能 自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计 DataGridView空间中加了list 的功能 自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计 lz你真是太有才列...以前也考虑过这个问题,但是都没有什么思路解决的看到你贴出来,哈哈好好学习,到时候lz搞出来了记得也给我来个小实例啊...[email protected]谢谢啊.... 你提供的网页里面有demo下载,你看看他的源程序就可以了。 因为是英文版的,所以没注意有Demo可以下载,呵呵...现在找到了;下载地址:http://download.microsoft.com/download/4/2/1/4215444a-ed19-45fe-84a9-2eb0b7b9dcbb/DataGridViewAutoFilter.zip想研究的,可以去下载,才247KB,很小的示例;----------------------------------------------------------------------------------------------------------------------------------我遇到了个问题,谁能帮我看看: //这个是Demo里面的Load事件代码: private void DesignerSetupForm_Load(object sender, EventArgs e) { // Load the sample data and resize the columns based on their contents. this.newDataSet.ReadXml(@"..\..\..\..\..\TestData.xml"); this.dataGridView1.AutoResizeColumns(); } //这个是我自己项目里面的Load事件代码: strSql = "select top 20 订单编号,贸易方式,价格条款 from dd订单"; SqlDataAdapter dap = new SqlDataAdapter(strSql, clsSql.cn); DataSet ds = new DataSet(); dap.Fill(ds, "dd订单"); dataGridView1.RowCount = ds.Tables[0].Rows.Count + 1; for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { this.dataGridView1.Rows[j].Cells[0].Value = ds.Tables[0].Rows[j]["订单编号"].ToString(); this.dataGridView1.Rows[j].Cells[1].Value = ds.Tables[0].Rows[j]["贸易方式"].ToString(); this.dataGridView1.Rows[j].Cells[2].Value = ds.Tables[0].Rows[j]["价格条款"].ToString(); } ds.Dispose();运行Demo,很正常,没有问题;但是运行我自己的项目,就报错了: 应该不用想楼上说的那些那么麻烦 我记得datagridviewRow 有一种就是下拉菜单的Row 可以先在初始化的时候插入第一行 剩下的就不用我说了吧 下载地址:http://download.microsoft.com/download/4/2/1/4215444a-ed19-45fe-84a9-2eb0b7b9dcbb/DataGridViewAutoFilter.zip 这个看来相当不错,收藏以后有时间再研究研究,呵呵。 话说 Delphi的第三方控件EhDBGrid里有一模一样的功能,而且有源代码可以参考,如果不介意是pascal的话 已解决:http://topic.csdn.net/u/20090530/16/e16b53a1-4539-4cdc-8607-9f7e1ed4fc90.html?819887468 为什么同样是去掉空字符,换个方法就不能输出了呢? 读取二进制问题,字节数组到结构体转换 给datagridview列添加控件后第一次显示不成功是怎么了 高人请进~C#利用远程桌面 弹出服务器上面的移动硬盘? 很多人问.NET入门以后怎么办,随便说两句我的看法 [举报]又一个倒分的!版主快来 运行时动态添加MenuItem的问题 文本框如何显示图片 怎样保存图片为空? listview图标显示,再线等待!! sql 优化 怎样把C#软件封装成安装软件
自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计
不明白这个,能否给个小小的示例代码段?
谁能把这个翻译, 贴个示例出来?
/// 触发CellPainting事件
/// </summary>
/// <param name="e"></param>
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
#region 画列头下拉框
if (isColumnHeaderFilter && e.RowIndex == -1 && e.ColumnIndex > -1)
{
string columnName = Columns[e.ColumnIndex].Name;
bool find = false;
foreach (string name in filterColumnNames)
{
if (string.Compare(name, columnName, true) == 0)
{
find = true;
break;
}
}
if (find)
{
e.PaintBackground(e.ClipBounds, false);
e.PaintContent(e.ClipBounds);
e.Paint(e.ClipBounds, DataGridViewPaintParts.SelectionBackground | DataGridViewPaintParts.Focus |
DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentBackground);
// 画按钮
Rectangle rect = GetColumnHeaderDropDownBounds(e.CellBounds);
e.Graphics.FillRectangle(SystemBrushes.ButtonFace, rect);
Point pLT = rect.Location;
Point pRT = new Point(rect.Right, rect.Top);
Point pLB = new Point(rect.Left, rect.Bottom);
Point pRB = new Point(rect.Right, rect.Bottom);
e.Graphics.DrawLine(SystemPens.ButtonHighlight, pLT, pRT);
e.Graphics.DrawLine(SystemPens.ButtonHighlight, pLT, pLB);
e.Graphics.DrawLine(SystemPens.ButtonShadow, pRT, pRB);
e.Graphics.DrawLine(SystemPens.ButtonShadow, pLB, pRB);
// 画三角形
Point p31 = new Point(pLT.X + (pRT.X - pLT.X) / 4, pLT.Y + (pLB.Y - pLT.Y) / 4);
Point p32 = new Point(pRT.X - (pRT.X - pLT.X) / 4, pLT.Y + (pLB.Y - pLT.Y) / 4);
Point p33 = new Point(pLT.X + (pRT.X - pLT.X) / 2, pLB.Y - (pLB.Y - pLT.Y) / 4);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
int[] columnList = new int[columnHeaderFilter.Keys.Count];
columnHeaderFilter.Keys.CopyTo(columnList, 0);
if (Array.IndexOf(columnList, e.ColumnIndex) == -1)
{
e.Graphics.FillPolygon(SystemBrushes.ControlText, new Point[] { p31, p32, p33, p31 });
}
else
{
e.Graphics.FillPolygon(SystemBrushes.ControlLightLight, new Point[] { p31, p32, p33, p31 });
}
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
e.Handled = true;
}
} #endregion base.OnCellPainting(e);
}
自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计
自己编写一个类,继承DataGridView,左键点击格网空白处时,弹出下拉列表进行功能设计
以前也考虑过这个问题,但是都没有什么思路解决的
看到你贴出来,哈哈
好好学习,到时候lz搞出来了记得也给我来个小实例啊...
[email protected]
谢谢啊....
下载地址:http://download.microsoft.com/download/4/2/1/4215444a-ed19-45fe-84a9-2eb0b7b9dcbb/DataGridViewAutoFilter.zip
想研究的,可以去下载,才247KB,很小的示例;-----------------------------------------------------------------
-----------------------------------------------------------------我遇到了个问题,谁能帮我看看: //这个是Demo里面的Load事件代码:
private void DesignerSetupForm_Load(object sender, EventArgs e)
{
// Load the sample data and resize the columns based on their contents.
this.newDataSet.ReadXml(@"..\..\..\..\..\TestData.xml");
this.dataGridView1.AutoResizeColumns();
}
//这个是我自己项目里面的Load事件代码:
strSql = "select top 20 订单编号,贸易方式,价格条款 from dd订单";
SqlDataAdapter dap = new SqlDataAdapter(strSql, clsSql.cn);
DataSet ds = new DataSet();
dap.Fill(ds, "dd订单");
dataGridView1.RowCount = ds.Tables[0].Rows.Count + 1;
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
this.dataGridView1.Rows[j].Cells[0].Value = ds.Tables[0].Rows[j]["订单编号"].ToString();
this.dataGridView1.Rows[j].Cells[1].Value = ds.Tables[0].Rows[j]["贸易方式"].ToString();
this.dataGridView1.Rows[j].Cells[2].Value = ds.Tables[0].Rows[j]["价格条款"].ToString();
}
ds.Dispose();运行Demo,很正常,没有问题;
但是运行我自己的项目,就报错了: