D
D
DD-var2020-05-11 15:33:14
C++ / C#
DD-var, 2020-05-11 15:33:14

How to add from string to datagridview?

I process values ​​from the Internet and add them to a string, how can I display this string in a grid?
for example:
received data on temperature about the weather at the moment. and add this value to the grid

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Collin, 2020-05-12
@DD-var

It depends on how exactly you are using the grid. Please post a code snippet.
Usually, a DataSource is used with a grid, for example, they bind a dataSet into it, which contains Tables.
It looks like this: (in place of "0" there may be "Table Name") In this case, we need to add a row to the Tables[0] table
dataGridView1.DataSource = dataSet.Tables[0];

dataSet.Tables[0].Rows.Add(); 
dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1][int номер ячейки, куда добавить string] = receivedData;

It needs to be clarified here that the rows and cells in are dataSet.Tablesindexed as
.Rows[int индекс строки][int индекс столбца/ячейки (Cells)]
, and in order to find out which our line was added (and it was added to the end), we, having learned the number of Rows.Countlines, subtract from Count1, because indexing in lists, arrays, etc. starts from 0, and Countit cannot be 0, if there is at least one row, it Countwill already be equal to 1.
The grid may need to be updated:
dataGridView1.Update();

V
Vladimir Korotenko, 2020-05-11
@firedragon

The date grid has a datasource call in my ds.Rows.Add(); in the returned object, populate the columns and call the data binding. If you don't understand, I'll write later.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question