Skip to content
Loading
  • Sachin Singh
    +1
    how many cells are you updating with the same value?
    as per your code you are trying to update three cells value with the same single value but in your question you are saying that only the fourth cell is editable , so what do you want to achieve here?
     why are you not doing this then, please confirm why are you using loop here?
    1. private void Update_Btn_Click(object sender, EventArgs e)  
    2.         {  
    3.             System.Text.StringBuilder sb = new System.Text.StringBuilder();  
    4.             int x = 3;  
    5.             DataTable dt = new DataTable();  
    6.             DataGridViewRow newDataRow = dataGridView1.SelectedRows[0];  
    7.             
    8.               
    9.               
    10.                 newDataRow.Cells[3].Value = textBoxOrd.Text;  
    11.                 sb.Append(dataGridView1.SelectedCells[3].RowIndex.ToString());  
    12.                 sb.Append(", Column: ");  
    13.                 sb.Append(newDataRow.Cells[3].Value.ToString());  
    14.                   
    15.             }  
    16.         } 
     
    +1
  • Sachin Singh
    +1
    @Rajnikant Sir,
     Thanks for pointing out , GridView webform edit update thing was in my mind while replying , i completely over looked that it is a normal button click.
    also i am not getting why is he using loop here , how many rows and column does he actually want to update with this?
    +1
  • Laxmidhar Sahoo
    +1
    hi
     
    your question is confusion
    +1
  • +1
    @ Sachin, sorry am new to C# and that was some sort of try and error. I have tried DataGridViewRow newDataRow = dataGridView1.Rows[e.SelectedRowIndex]; but no success yet.
     
    For now. I can select the row and display the data in text boxes, I am trying to update  one cell "[3] "of from the selected row, however I end up updating just the same cell. instead of updating the cell "[3]" of the selected row.
     
    ----------------------------------------------------------------- I realise that was a little confusing! le me summarise it below--
     
    1) I open a csv file from  a local location and display it in a datagridview.
    2) I select one of the colums and the data is displayed in 4 test boxes from each column.
    3) the First 3 textboxes are read only, so I only change the data in the fourth text box which I save back to the data grid view.
    4) I export the adjusted csv file to another folder on the computer.
     
    * Problem is 3. after editing the data, it only gets saved to one cell
    +1