Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make the specific text change to the other font style after regex expression.

string c = dataGridView1.Rows[e.RowIndex].Cells["data"].Value.ToString();
//MessageBox.Show(c);
//c = Transfer data to https://www.mylink.com/folder/

I able to get https://www.mylink.com/folder/ after using regex. and I try to use this code, but it will make all the text in the cell change to this font style.
dataGridView1.Columns["data"].DefaultCellStyle.Font = new Font("Lucida Console", 7, FontStyle.Bold);


Any suggestions if I want only part of the text change to the other font style?

What I have tried:

string c = dataGridView1.Rows[e.RowIndex].Cells["data"].Value.ToString();
//MessageBox.Show(c);
//c = Transfer data to https://www.mylink.com/folder/
            Regex r = new Regex(@"(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/,]*");
            Match m = r.Match(c);
            if (m.Success)
            {
               //....
            }
Posted
Updated 30-Mar-22 0:29am

1 solution

DataGrid view cells don't have any formatting on a character-by-character basis - the only applicable font format applies to all text in a cell.

To do what you want, you would have to handle the CellPainting[^] event and draw your own text completely.

That's not trivial. Not that difficult either, but not trivial.
 
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