winform程序已经取得数据
datagridview1.datasource = dsTable.Tables[0];现在我想对其中某一列名为website的列,设置成linklable,点击一下就能弹出网页
请问代码该怎么写的??

解决方案 »

  1.   

    http://hi.baidu.com/jzfkj/blog/item/bb0143d46bc0d0ce50da4bcb.html
      

  2.   


    //添加列
                DataGridViewColumn col = new DataGridViewLinkColumn();
                col.DataPropertyName = "url";//字段
                dataGridView1.Columns.Add(col);
                dataGridView1.Rows.Add(10);
                foreach(DataGridViewRow row in dataGridView1.Rows)
                {
                    row.Cells[0].Value = row.Index;
                }
    //打开
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex == 0)
                {
                    Process.Start("http://"+dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                }
            }
      

  3.   

    楼上两位,你们给的结果都是在datagridview的末尾,添加了一列新列。
    但是我的要求不是在末尾添加
    我是要在本来就显示的website列,将其设置成linklable列当然了,按照你们的做法,我把原来的website列隐藏也可以实现
    但问题是,这样一来,顺序就乱了。我想直接实现对website列的改变,而不是最后再新加一列
      

  4.   

    datagridview中有linklable列,叫做DataGridViewLinkColumn,在编辑列的时候直接把website那一列变成DataGridViewLinkColumn就可以了,
    之后的点击打开网页的代码就像2楼所说的那样了。
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex == 0)
                {
                    Process.Start("http://"+dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                }
            }其实2楼已经给你答案了,只是你不会灵活运用呀。
      

  5.   

     将website列的ColumnType属性改为DataGridViewLinkColumn就可以了
      

  6.   


    楼上是对的,通过ColumnType各种控件样式都可以设置
      

  7.   


    恕我愚钝,我没找到ColumnType属性
    我声明一下,我是在代码里指定数据源的,并不是在设计的时候编辑列里指定的
    这样说吧
    我其实没什么设计,直接把datagridview拖进窗体
    然后在窗体事件里用代码对其绑定数据源,就是先从数据库取得dataset,然后赋值给datagridview虽然用datagridview.columns["WebSite"].GetType,  能得到当前的类型
    但我没找到怎么设置
      

  8.   

    for (int 行 = 0; 行 < 编辑控表.RowCount - 1; 行++)
                    {
                        for (int 列 = 0; 列 < 编辑控表.ColumnCount; 列++)//改变列属性
                        {
                            DataGridViewLinkCell 超链接列 = new DataGridViewLinkCell();
                            if (编辑控表.Rows[行].Cells[列].Value.ToString().IndexOf("http://") == 0)
                            { 编辑控表.Rows[行].Cells[列] = 超链接列; }
                        }
                    }
      

  9.   

    如果再不知道怎么办我就没办法了创建连接列            DataGridViewLinkColumn WebSiteColumn= new DataGridViewLinkColumn();
                WebSiteColumn.DataPropertyName = "WebSite";
                WebSiteColumn.HeaderText = "WebSite";
                dataGridView1.Columns.Add(WebSiteColumn);
      

  10.   


    你这个add方法是在最后面添加了一列
    楼主要求的是改变原本website列的显示样式
    根本不是一个概念啊
    要添加一个列还不简单吗?汗死了。