Asp.Net教程,WinForm教程,Asp.Net MVC,vs2008教程,vs2010教程,Silverlight技术,源码下载,Asp.Net视频教程
全站热门标签
vs2010 Silverlight 存储过程 水晶报表 ADO.NET JavaScript LINQ AjaxPro DataGridView 面向对象 Extjs GridView XML DevExpress HTML教程 Oracle jQuery 分页 Prototype教程 GDI+ Visual C++2010 MySQL Office2010 WPF MVC Dojo WCF4.0 VB.NET Sql2005 textbox cookie WCF WinForm Discuz!NT SQL经典语句 T-SQL checkbox ASPxGridView F# asp.net SQL VS2008新特性 DropDownList Access TreeView Ajax VS2008 页面执行时间 Flex 字符串 回调 VB2005 DataSet C#时间 ASP.NET性能优化 用户在线检测
FrameworkC#技术 VB.NET VC.NET WCF WPF
当前位置: 主页 > WinForm教程 > C#技术 >

在DataGridView列中表示链接

时间:2010-06-26 01:21来源:未知 作者:admin 点击:

注意:DataGridView控件是从.NET Framework 2.0版本开始追加的。

在DataGridView的列中想表示和LinkLabel控件一样的链接时,可以使用DataGridViewLinkColumn来实现。DataGridViewLinkColumn类的使用和在这里的DataGridViewButtonColumn使用方法基本相同。


 

 下面在例子是在DataGridView中追加链接列的代码。

[C#]

//DataGridViewLinkColumn作成
DataGridViewLinkColumn column = new DataGridViewLinkColumn(); //设定列的名字
column.Name = "Link"; //所有的链接文字列表示为"点击阅览"
column.UseColumnTextForLinkValue = true;
column.Text = "点击阅览"; //鼠标停留在链接上时显示下划线
column.LinkBehavior = LinkBehavior.HoverUnderline; //设定为不能自动访问
column.TrackVisitedState = true; //向DataGridView追加
DataGridView1.Columns.Add(column);

获得链接被点击

获得链接被点击的方法也和DataGridViewButtonColumn一样,使用DataGridView.CellContentClick事件实现。

补充:CellClick事件,在单元格内不是链接的部分点击时也会被触发。

下面的例子就是获得第几行的链接被点击的代码。

[C#]

//CellContentClick事件处理器
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView dgv = (DataGridView)sender; //如果是"Link"列,被点击
if (dgv.Columns[e.ColumnIndex].Name == "Link")
{ MessageBox.Show(e.RowIndex.ToString() + "行的链接被点击了。"); //已经访问
DataGridViewLinkCell cell = (DataGridViewLinkCell)dgv[e.ColumnIndex, e.RowIndex]; cell.LinkVisited = true; }
 }
(责任编辑:admin)
Tags:DataGridView 链接
责任编辑:admin
返回顶部
------分隔线----------------------------
推荐内容
骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价 骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价