+1 vote
183 views

I have a datagridview in c# with rows , i need to bring the item which is select from combobox ..If value of combobox matches with datagridview particular cell then it should come at first.

How to achieve the same in C#.net forms app ?

Category
asked Jul 23, 2016 | 183 views

+1 vote

Below im searching for productname which is available in datagridview column cell 2 , I achieved the result with following code :

String searchValue = cmbProductName.Text; int rowIndex = -1;           foreach (DataGridViewRow row in dgvBarcodePrinting.Rows) { if (row.Cells[2].Value.ToString().Equals(searchValue)) { rowIndex = row.Index; break; } } dgvBarcodePrinting.Rows[rowIndex].Selected = true; dgvBarcodePrinting.FirstDisplayedScrollingRowIndex = dgvBarcodePrinting.SelectedRows[0].Index; 

edited Jul 23, 2016

You can simple use jQuery CSS method to change the color of the selected row. You have to use this method on the change event of combobox.

For this you have to give some class to your combo box.

<select class="cmbbox">
<option value="val1">text1</option>
<option value="val2">text2</option>
<option value="val3">text3</option>
</select>

Then use the change event of it to change the color of the particular row.

\$(".cmbBox").change(function() {
//change the row color using jquery css method
})

In this way you can even do other tasks easily.