Can you help me with this..
For Each r As DataGridViewRow In dglist.Rows
For Each c As DataGridViewCell In r.Cells
If c.Value IsNot Nothing Then
**If c.Value.ToString = Label2.Text.ToString Then
c.Value.ToString.Trim.Replace(c.Value.ToString.Trim, TextBox1.Text)
End If**
'MessageBox.Show(c.Value.ToString)
End If
Next
Next
I need to replace the value of the cell with the value of the label.
But still my code did not work.
You need to assign the value (to cell value property) rather than operate on the value of string you have. When you do an operation like
ToStringetc an additional instance in memory is created and that’s all if you are not assigning it. Do this instead:Reconsider your if clauses since I am not very sure that’s what you are looking for. In your question you say you want to assign the value of label, but in the code you pasted it seemed to me that you are after text value of your text box.