How to add data correctly to a cell in a DataGridView?

  • Thread starter Thread starter DominusDRR
  • Start date Start date
D

DominusDRR

Guest
Hi

Im reading a TXT file and I want to add data to the cells in a DataGridView named GrillaDatos.

To add the data I do the following:

GrillaDatos[0, GrillaDatos.RowCount - 1].Value = Convert.ToString(GrillaDatos[0, GrillaDatos.RowCount - 1].Value) + Convert.ToChar(Valor);


Where initially GrillaDatos.RowCount initially equals 1.

And Valor is a variable of type ushort.

This part of the code works OK, add bytes to the cell.

When I want to add a new column, we perform the following:

GrillaDatos.RowCount++;


When I return to my routine invoke explained at the beginning, I discovered that the value in the previous row disappears and values before the new row is added.


For example, suppose that in the beginning GrillaDatos.RowCount = 1;


I add data to the first row:


GrillaDatos[0, GrillaDatos.RowCount-1].Value = “Hello”


This means that:


GrillaDatos[0, 0].Value = “Hello”

Then I increase a row:


GrillaDatos.RowCount++;

Now I add information to the new row:

GrillaDatos[0, GrillaDatos.RowCount-1].Value = “Bye”


But when I check the status of the cells of the object I get the following:


GrillaDatos[0, 0].Value = null

GrillaDatos[0, 1].Value = “HelloBye”


Any suggestions?

Thanks in advance

Continue reading...
 
Back
Top