Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim DataGridView1 = New DataGridView
      'add columns to DGV
      DataGridView1.Columns.Add("Year", "Year")
      DataGridView1.Columns.Add("Make", "Make")
      DataGridView1.Columns.Add("Model", "Model")
      DataGridView1.Columns("Year").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
      DataGridView1.Columns("Make").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
      DataGridView1.Columns("Model").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
      DataGridView1.RowHeadersVisible = False

      'add items to DGV
      DataGridView1.Rows.Add("2010", "Chevrolet", "Camaro")
      DataGridView1.Rows.Add("2006", "Ford", "Mustang")
      DataGridView1.Rows.Add("2008", "Dodge", "Charger")
      DataGridView1.Rows.Add("2007", "Chevrolet", "Corvette")

In this Datagridview if i type "ro" in a text box i need any column that having "ro" (eg: Chevrolet,Camaro ) should be highlight. Please give me a solution for this
Posted
Comments
MuhammadUSman1 4-Oct-14 5:54am    
Check Solution 1 if any Question then let me know.

1 solution

You can use cell formate event or use following code.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting%28v=vs.110%29.aspx[^]

C#
 for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells["Make"].Value.ToString().ToUpper().Contains("ro"))
                    {
                        dataGridView1.Rows[i].Cells["Make"].Style = new DataGridViewCellStyle() { Font = new Font(dataGridView1.Font, FontStyle.Bold), ForeColor = Color.DodgerBlue };
//it will change cell forecolor you can use according to you required action
// same like forecolor you can change backcolor or cell and also row.

                    }
//ro 
// or you can use textbox value.
                    if (dataGridView1.Rows[i].Cells["Model"].Value.ToString().ToUpper().Contains(txtBox1.Text))
                    {
                        dataGridView1.Rows[i].Cells["Model"].Style = new DataGridViewCellStyle() { Font = new Font(dataGridView1.Font, FontStyle.Bold), ForeColor = Color.DodgerBlue };

// for full row colors you can use following
// dataGridView1.Rows[i].DefaultCellStyle = new DataGridViewCellStyle() { Font = new Font(dataGridView1.Font, FontStyle.Bold), ForeColor = Color.DodgerBlue, BackColor = Color.Green };
                    }                   
		}



if any question then let me know.

-> M.U
 
Share this answer
 
v2
Comments
Moses Geo 6-Oct-14 4:36am    
Thank you for your help Mr.MuhammadUSman Now It is working
Moses Geo 6-Oct-14 4:41am    
Can you help me for my another question Please ......
http://www.codeproject.com/Questions/826214/Increase-printing-speed-on-Dot-matrix-printer-Usin

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