Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have datagridview column containing Item Names and search texBox. I am able to search items in columns using search text. But problem is that I want to change forecolor of datagridview cell text matching with search textbox text.
Posted

You want exactly three links, but the last one is the most important:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.style.aspx[^] (read Remarks section thoroughly),
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle.aspx[^]
,
Microsoft Q209354.

Please, no offense, OK? This is what you really need: the ability to find out things in documentation, especially such trivial things.

[EDIT]

Please read on customization: http://msdn.microsoft.com/en-us/library/ms171618%28v=vs.110%29.aspx[^].

You can render custom image of the cell: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellpainting%28v=vs.80%29.aspx[^].

Using the instance of System.Drawing.Graphics, draw your text in parts: selected and unselected parts in different color.

—SA
 
Share this answer
 
v2
Comments
Ravndra22 13-Feb-13 23:49pm    
Sergey-I dont want to change forecolor of whole cell, I want to highlight some text of cell which match with search text
Sergey Alexandrovich Kryukov 13-Feb-13 23:55pm    
Selected only? No, a text cell only support text. You can create a custom cell class, which would render formatted text, RTF, maybe...
—SA
Ravndra22 14-Feb-13 0:10am    
Can you give me hint to where to start?
Sergey Alexandrovich Kryukov 14-Feb-13 0:51am    
From the class System.Windows.Forms.DataGridViewCell as a base class. You will see what derived classes are already there:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.aspx
—SA
Sergey Alexandrovich Kryukov 14-Feb-13 0:54am    
Please see my updated answer, after [EDIT]. It will take some time and effort...
—SA
 
Share this answer
 
Comments
Espen Harlinn 14-Feb-13 16:29pm    
Nice link :-D
Shubh Agrahari 17-Feb-13 7:56am    
ya its ma pleasure boss.

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