在Winform的DataGridView的单元格中同时显示文本和图标,以及树形结构的示例
来源:互联网 发布:前后端数据交互方式 编辑:程序博客网 时间:2024/06/05 09:14
(原创文章,转载请注明来源:http://blog.csdn.net/tyouvivi/article/details/1676850)
- 树形结构的DataGridView:Customizing the DataGridView to support expanding/collapsing (ala TreeGridView) DataGridView
TreeGridView 修正版本:
Some people reported problems actually running the TreeGridView sample, so I've recompiled it on an RTM build machine (previously I was using the latest internal VS build). You can get the new version (that also includes release & debug binaries prebuilt) here: http://www.windowsforms.net/blogs/markrideout/TreeGridViewRebuilt.zip
- 单元格中同时显示文本和图标
The DataGridView control does not have any built-in support for showing an icon and text in the same cell. Through the different painting customization events, such as the CellPaint event, you can easily display an icon next to the text in the cell.
The following example extends the DataGridViewTextColumn and cell to paint an image next to the text. The sample uses the DataGridViewCellStyle.Padding property to adjust the text location and overrides the Paint method to paint an icon. This sample can be simplified by handling the CellPainting event and performing similar code.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing;namespace JrtGenerator.Utility{ public class TextAndImageColumn : DataGridViewTextBoxColumn { private Image imageValue; private Size imageSize; public TextAndImageColumn() { this.CellTemplate = new TextAndImageCell(); } public override object Clone() { TextAndImageColumn c = base.Clone() as TextAndImageColumn; c.imageValue = this.imageValue; c.imageSize = this.imageSize; return c; } public Image Image { get { return this.imageValue; } set { if (this.Image != value) { this.imageValue = value; this.imageSize = value.Size; if (this.InheritedStyle != null) { Padding inheritedPadding = this.InheritedStyle.Padding; this.DefaultCellStyle.Padding = new Padding(imageSize.Width, inheritedPadding.Top, inheritedPadding.Right, inheritedPadding.Bottom); } } } } private TextAndImageCell TextAndImageCellTemplate { get { return this.CellTemplate as TextAndImageCell; } } internal Size ImageSize { get { return imageSize; } } } public class TextAndImageCell : DataGridViewTextBoxCell { private Image imageValue; private Size imageSize; public override object Clone() { TextAndImageCell c = base.Clone() as TextAndImageCell; c.imageValue = this.imageValue; c.imageSize = this.imageSize; return c; } public Image Image { get { if (this.OwningColumn == null || this.OwningTextAndImageColumn == null) { return imageValue; } else if (this.imageValue != null) { return this.imageValue; } else { return this.OwningTextAndImageColumn.Image; } } set { if (this.imageValue != value) { this.imageValue = value; this.imageSize = value.Size; Padding inheritedPadding = this.InheritedStyle.Padding; this.Style.Padding = new Padding(imageSize.Width, inheritedPadding.Top, inheritedPadding.Right, inheritedPadding.Bottom); } } } 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) { // Paint the base content base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (this.Image != null) { // Draw the image clipped to the cell. System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer(); graphics.SetClip(cellBounds); graphics.DrawImageUnscaled(this.Image, cellBounds.Location); graphics.EndContainer(container); } } private TextAndImageColumn OwningTextAndImageColumn { get { return this.OwningColumn as TextAndImageColumn; } } }}
- 在Winform的DataGridView的单元格中同时显示文本和图标,以及树形结构的示例
- C# Winform datagridview 在一个单元格中 同时存在文本和按钮
- winform的DataGridView合并单元格
- C#如何在DataGridView的RowHeader显示字符串和图标
- winform DataGridView双击修改单元格的值
- C# .NET 如何在DataGridView中最简洁的实现对单元格显示的处理
- C#中对Winform中的DataGridView的控制技巧。(单独控制某单元格的按钮不显示、某单元格的ReadOnly)
- C# winform中,动态绑定textbox,combox,datagridview的示例
- winform中datagridview 在单元格选中状态下(非编辑状态)输入一个字符产生重复的问题
- WinForm 2.0 textBox作为参数的查询,显示在DataGridView
- C#中datagridview使用tooltip控件显示单元格内容与datagridview自带的tooltip显示单元格内容的方法
- SQLserver--用存储过程在winform的dataGridView空间中显示数据库表
- winform中DataGridView的基本操作以及简单绑定
- WinForm 中DataGridView不显示最后空白的行
- C# winform 双击DataGridView的一单元格,把内容存储在剪贴板
- Winform的DataGridView控件在编辑单元格时事件触发顺序
- [WinForm]DataGridView选中一行获取指定单元格的值
- Winform下DataGridView评分单元格的痛苦折磨
- Java解析XML的四种方法
- VLC源码分析总结
- MFC深入浅出之二MFC和Win32-李进久
- 2013年3月编程语言排行榜:有毒的Java
- LIVE555 使用流程
- 在Winform的DataGridView的单元格中同时显示文本和图标,以及树形结构的示例
- Spring事务传播性与隔离级别
- 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstrain
- ibatis集成spring 声明式事务管理
- Ubuntu下搭建TQ2440的程序下载环境
- 2013年4月编程语言排行榜:Objective-C的瓶颈
- 打印Web所需区域的实现
- Solr查询参数简介
- Java调用本地库,如调用DLL或者SO,如:JNI, Jawin, Jacob,JNative,JNA