使用数据表与列HREF链接的datagridview [英] datagridview using a datatable with a column href link

查看:136
本文介绍了使用数据表与列HREF链接的datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何让我的C#的winform项目有界的datagridview栏,显示像一个href链接。问题是,链接点击的作品,但任何普通用户不会意识到,因为它显示为一个字符串,他们可以单击该字段。我需要的领域显示为蓝色,带有下划线,鼠标指针会变成手形......等等。

I'm trying to figure out how to get a bounded datagridview column in my c# winform project to show up like an href link. The thing is that the link click works but any average user wouldn't realize that they can click the field since it's displayed as a string. I need the field to show up as blue, with underlines, the mouse pointer turns into a hand ...etc.

我能够此前做到这一点时,我是用我的Datagrid的数据集。我去了设计师,选择添加列,并增加它作为一个DataGridViewLinkColumn。我最近改变了项目中使用数据表,我意识到,田野不再显示为可点击(如果我点击它,虽然工作)。

I was able to accomplish this previously when I was using Datasets with my Datagrid. I went to the designer and selected "Add Column" and added it as a 'DataGridViewLinkColumn". I've recently changed the project to use datatables and I realized that the fields no longer show up as clickable (if I click it does work though).

任何理想如何相对轻松地做到这一点?我已经搜查,我有些诧异,我似乎无法找到一个简单的解决方案。

Any ideal how to accomplish this with relative ease? I've searched and I'm somewhat surprised that I cannot seem to find a simple solution.

推荐答案

更改那些链接是细胞的类型 DataGridViewLinkCell ,然后处理单击该单元格,像这样的:

Change the type of the cells that are links to be a DataGridViewLinkCell and then handle the click on the cell, like this:

void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow r in dataGridView1.Rows)
    {
        if (System.Uri.IsWellFormedUriString(r.Cells["Links"].Value.ToString(), UriKind.Absolute))
        {
            r.Cells["Links"] = new DataGridViewLinkCell();
            DataGridViewLinkCell c = r.Cells["Links"] as DataGridViewLinkCell;
        }
    }
}

// And handle the click too
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewLinkCell)
    {
        System.Diagnostics.Process.Start( dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string);
    }
}

这篇关于使用数据表与列HREF链接的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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