Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview with 2 columns in this program.

I want to make part of the string to clickable link and the info in datagridview will extracted from xml file.

<?xml version="1.0" encoding="utf-8" ?>
    <list checkList="Update items in https://mylinks"> </list>
    <list checkList="xxxxxx"></list>
    <list checkList="xxxxxx"> </list>

I found the page that had explain to make the column hyperlink But it will make all the info in that column in hyperlink style.

Any suggestion that just to make part of string become clickable like shown in xml file above?

What I have tried:

public checkList chkListConfig()
            //Parse List.xml
            XmlSerializer deserializer = new XmlSerializer(typeof(checkList));
             TextReader reader = new StreamReader(Directory.GetCurrentDirectory() +  @"\list.xml");
            checkList config = (checkList)deserializer.Deserialize(reader);
            return config;

        public DataTable checkListData()
            DataTable data = new DataTable();

            data.Columns.Add("ChkList", typeof(string));
            data.Columns.Add("Click", typeof(bool));

            checkList chkList = chkListConfig();

            foreach(var c in chkList.chk.List)
                data.Rows.Add(c.cfg, false);

            return data;
Updated 14-Mar-22 2:34am

I suggest having a RichTextBox cell in the DataGridView - a CP article on how to do that can be found here : RichTextBox Cell in a DataGridView[^]
You can then have the hyperlink embedded in the RTF - see Display Web-Style Links with RichTextBox Control - Windows Forms .NET Framework | Microsoft Docs[^]
Share this answer
Take a deep look at the code under the link you provided.
There's a dgv_CellContentClick event which you have to change to your needs. In the example entire text of cell is used, but you can use only the part of it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900