Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

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

$
0
0

Hi

I'm reading a TXTfile andI want toadd data to the cells in aDataGridViewnamedGrillaDatos.

To add the dataI do the following:

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

Whereinitially GrillaDatos.RowCountinitiallyequals 1.

AndValor is a variable oftypeushort.

This part of thecode worksOK, add bytesto the cell.

When Iwant to adda new column, we performthe following:

GrillaDatos.RowCount++;

WhenI return to my routineinvokeexplainedat the beginning, I discoveredthat the value inthe previous rowdisappears andvalues beforethe new rowis added.

For example, suppose that inthe beginningGrillaDatos.RowCount= 1;

I adddatato the first row:

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

This means that:

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

Then Iincrease a row:

GrillaDatos.RowCount++;

Now I addinformation to thenew row:

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

But whenI check the statusof the cellsof the objectI getthe following:

GrillaDatos[0, 0].Value = null

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

Any suggestions?

Thanks in advance


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>