+1 vote
104 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 ?

asked Jul 23, 2016 in Computer Science - IT by kevin | 104 views

2 Answers

+1 vote
Best answer

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;


answered Jul 23, 2016 by kevin
edited Jul 23, 2016 by slow_learner
0 votes

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.

answered Feb 25 by RohitNath