Tag: datagridview

在C#中合并RTL Datagridview列标题

我想合并3个Datagridview列标题(第3个,第4个和第5个) 列)和Datagridview的RightToleft属性已启用。 我是用户 这段代码: private void PromotionButton_Click(object sender, EventArgs e) { dataGridView1.ColumnHeadersHeight = dataGridView1.ColumnHeadersHeight * 2; dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting); dataGridView1.Paint += new PaintEventHandler(dataGridView1_Paint); dataGridView1.Scroll += new ScrollEventHandler(dataGridView1_Scroll); dataGridView1.ColumnWidthChanged += new DataGridViewColumnEventHandler(dataGridView1_ColumnWidthChanged); } private void dataGridView1_Paint(object sender, PaintEventArgs e) { for (int j = 2; j -1) { Rectangle r2 = e.CellBounds; […]

如何仅绘制DataGridView的单元格背景而不是其内容?

我只需要绘制DataGridView单元格的背景而不是它的Content.But,而我正在绘画时它也会绘制其内容。请帮助我。 我的代码是这样的。 private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex == 0 ) { using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor)) { using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Clear cell e.Graphics.FillRectangle(backColorBrush, e.CellBounds); //Bottom line drawing e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1); e.Handled = true; } } […]

C# – 如何在删除行后刷新DataGridView

在我的代码中,我需要在重复间隔后从DataGridView中删除行,所以当计时器到期时我调用以下函数: private void removeRows(DataGridView dgv) { foreach (DataGridViewRow row in dgv.Rows) { // if some condition holds dgv.Remove(row); } dgv.Refresh(); } 我知道这些行已成功从DataGridView中删除,但它们仍然因任何原因仍保留在显示中。 关于我可能做错的任何提示?

在winform应用程序的数据网格视图中添加上下文菜单

右键单击DataGridView中的菜单项时如何显示上下文菜单? 我想在菜单中添加删除,以便删除整行。 提前致谢

在UserControl中公开DataGridView的Columns属性,并使其可通过Designer进行编辑

简短的介绍: 我有一个带有DataGridView的UserControl。 我想将DataGridView Columns集合暴露给设计器,因此我可以在设计时更改User Control上的列。 问题:我需要哪些设计师属性? 对于那些对较长版本感兴趣的人: 我有一个具有以下function的UserControl: 一个DataGridView,显示集合中项目的“页面”。 一个NumericUpdown控件,用于选择要显示的页面。 页面向上/向下翻页按钮,在显示第一页/最后一页时将禁用 可视地标记对显示项目的更改 用于保存/放弃更改的按钮。 此用户控件可以自动运行。 它有一个由父控件使用的函数: 显示页面(要显示的项目集合) UserControl引发了两个事件: 事件页面已更改(带有页码)。 应该导致加载新页面 事件保存项目(包含已更改项目的集合) 我必须在几个表单上显示此用户控件。 唯一的区别是DataGridViewColumn的集合因表单而异。 我可以通过编程方式添加列,但使用设计器创建它们会更容易。

将datagrid视图背景设置为透明

我试图将数据网格视图的背景颜色设置为从属性“透明”,但它表示“不是有效的属性”。 我该怎么做?

按钮列的DataGridView图像

我正在尝试将可点击的图像/按钮添加到datagridview按钮列。 图像/按钮将是播放或停止的图标。 如果用户单击播放按钮,则启动系统上的服务,如果用户单击停止按钮,则服务停止。 我已经编写了启动和停止服务的函数。 我遇到的困难是让按钮/图像显示在数据网格中并使其可点击。 这是我对代码的看法: this.dgrdServices.RowPrePaint +=new DataGridViewRowPrePaintEventHandler(dgv_RowPrePaint); this.dgrdServices.Rows.Add(); this.dgrdServices.Rows[0].Cells[0].Value = Image.FromFile(@”C:\users\brad\desktop\green-dot.gif”); this.dgrdServices.Rows[0].Cells[1].Value = “MyServer”; this.dgrdServices.Rows[0].Cells[2].Value = “MyService”; this.dgrdServices.Rows[0].Cells[3].Value = “Started”; this.dgrdServices.Rows[0].Cells[4].Value = new DataGridViewButtonCell(); this.dgrdServices.Rows[0].Cells[5].Value = “Uninstall”; 如果最好使用一个图像按钮或一个可点击的图像,我就无法解决。 我也无法正确显示按钮。 谢谢Brad

C#DataGridView:当列是右对齐时,长文本在左侧以“…”截断

我有一个关于单元格截断的问题(替换为“…”): 当列右对齐时,如何在单元格的左侧显示替换“…”? 我使用非等宽字体,所以我不能只计算字符来做一些字符串操作作为解决方法,我需要一个解决方案。 我相信应该有。 为了说明我的问题,我在这里模拟我的DataGridView Left Context (Right aligned column) | Center Word | Right Context (Left aligned column) left context not truncated | CenterWord | Right context not truncated …Here is the long left context truncated | CenterWord | Here is the long right context truncated… 我想我已经说清楚了。 谢谢。 请帮帮我。 彼得 PS:同样的问题可以在这个链接找到: http : //objectmix.com/csharp/341736-datagridview-cell-format-question.html

是否可以在datagridview中切换行和列?

我在DataTable中有10条数据记录,其中包含3个字段“Foo”,“Bar”和“Baz”。 如果我将它连接到DataGridView,我会看到10行和3列,列标题显示字段的名称。 我想知道反转行和列是多么容易,因此使用相同的数据我最终得到3行和10列,字段名称显示在行标题中。 我可以手工做一些事情,比如重写OnPaint方法并将字段名称直接绘制到行标题单元格中,但我正在寻找更自动化的东西。 同样,有一个建议是手动交换值,但除非我将所有值都设置为字符串,否则这不会起作用。 数据表中的3列 – 类型为int,float和string的Foo,Bar和Baz不会转置。 即使我管理了所有这些手动更改,我的数据网格也有CheckBox列,ComboBox列 – 没有这样的行对应存在 – 没有CheckBox行或ComboBox行。 我目前只需要告诉编译器“添加一个ComboBoxColumn”,我必须重新编写,以便每个单元格都是单独生成的。 理想情况下,我想要一个TransposableDataGridView,它暴露了DataGridView的所有function,并附加了一个bool属性“Transposed”。 这样我就可以完全保留我的所有代码 – 除了网格的类型之外,我不需要改变任何东西。 如果不存在这样的情况,我可能只需要去写它。 (应该只花一年时间!:)

二维Integer数组到DataGridView

我如何在C#.Net 4.0中的DataGridView控件中显示二维整数数组?