Answer the question
In order to leave comments, you need to log in
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
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;
dataSet.Tables
indexed 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.Count
lines, subtract from Count
1, because indexing in lists, arrays, etc. starts from 0, and Count
it cannot be 0, if there is at least one row, it Count
will already be equal to 1. dataGridView1.Update();
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 questionAsk a Question
731 491 924 answers to any question