Note that there are some explanatory texts on larger screens.

plurals
  1. POfirst locating, then changing the value of a cell in a selected row in a datagridview?
    text
    copied!<p>Im trying figure out how I can change the value of a specific cell in a selected row of a datagridview. I am able to change the value but not in the highlighted row, only the first one. The hghlighting of the row is defined in the "find" button code.</p> <p>For example: I enter a text, it search each row for that text in the specific column and then scrolls to and highlights/selects the entire row. (This Works Fine)</p> <p>I then want to be able to get the value of a specific cell of the highlighted row by selecting the column name already present in the dropdownlist(combobox). It then gets the value of that cell and deducts from it a value present in a numericalUpDownCounter(nudQTY).</p> <p>So far i can do this for different cells selected by column name (cbSupplList) but it only does it for the first row not the highlighted row defined by the "Find" button Code.</p> <p>The following is my attempt so far:</p> <pre><code> private void btnFind_Click(object sender, EventArgs e) { /* Code to search the alphanumneric Part Number (in Column1 header called "PART NUMBER") and highlihgt the row*/ foreach (DataGridViewRow row in dataGridView1.Rows) { // Removes the row selection row.Selected = false; var cellValue = row.Cells["PART NUMBER"].Value; if (cellValue != null &amp;&amp; cellValue.ToString() == tbPartNum.Text.ToUpper()) { // Scrolls the found row up and highlights the entire row row.Selected = true; dataGridView1.FirstDisplayedScrollingRowIndex = row.Index; } } } private void btnSold_Click(object sender, EventArgs e) { int cellVal; int newCellVal; cellVal = Convert.ToInt32(dataGridView1.CurrentRow.Cells[cbSuppList.Text.ToString()].Value); newCellVal = Convert.ToInt32(cellVal - nudQty.Value); dataGridView1.CurrentRow.Cells[cbSuppList.Text.ToString()].Value = newCellVal; } </code></pre> <p>It seems it may have to do with the SELECTED ROW in the "Find" code and the CURRENT ROW in the "Sold" Code. Making the SELECTED.ROW = CURRENT.ROW would solve it.... any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload