为 Winforms DataGrid 控件添加超链接列 [英] Add a hyperlink column for a Winforms DataGrid control

查看:27
本文介绍了为 Winforms DataGrid 控件添加超链接列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 Winforms DataGrid 控件添加超链接列?

How can I add a hyperlink column for a Winforms DataGrid control?

现在我正在添加一个这样的字符串列

Right now I am adding a string column like this

DataColumn dtCol = new DataColumn(); 
dtCol.DataType = System.Type.GetType("System.String");
dtCol.ColumnName = columnName;
dtCol.ReadOnly = true;
dtCol.Unique = false;
dataTable.Columns.Add(dtCol);

我只需要它是一个超链接而不是一个字符串.我在框架 3.5 中使用 C#

I just need it to be a hyperlink instead of a String. I am using C# with framework 3.5

推荐答案

使用 DataGridViewLinkColumn.

该链接显示了设置列并将其添加到 DGV 的示例::

The link shows an example of setting up the column and adding it to a DGV::

DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.UseColumnTextForLinkValue = true;
links.HeaderText = ColumnName.ReportsTo.ToString();
links.DataPropertyName = ColumnName.ReportsTo.ToString();
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;

DataGridView1.Columns.Add(links);

您可能会对 此示例 显示了上面的代码段如何适合在运行时配置 DGV 列的更完整示例.

You'll probably be interested in this example that shows how the snippet above fits into a more complete example of configuring DGV columns at runtime.

这篇关于为 Winforms DataGrid 控件添加超链接列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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