I have a client-server program and the server receives [Process ID, Hostname, App Name, File Path] and I want to put them in a table. As of now they are sent in one string. Is DataGridView applicable to use even if they are not inside a database or is there another option?
Thanks.
The short answer is Yes.
List<T> as DataSourceDataTable as DataSource (DataTable not related to db)DataSource and only defining columns and adding rowsUse with List<T> as DataSource for example:
var data= new List<DataClass>();
data.Add(new DataClass(){Property1=1 , Property2= "One" });
data.Add(new DataClass(){Property1=2 , Property2= "Two" });
data.Add(new DataClass(){Property1=3 , Property2= "Three" });
dataGridView1.DataSource= data;
And the result will be a dataGridView with 2 columns (Property1, property2) and 3 rows.
In above example, DataClass is a class like the following:
public class DataClass { public int Property1 {get; set;} public string Property2 {get; set;} }
For more advance scenarios you can use DataSource window to add new DataSource to your project. You can add Object datasource as well.
use with a DataTable as DataSource
You can create a DataTable and add your columns to it using dataTable.Columns.Add then add your rows using dataTable.Rows.Add and then set it as DataSource of grid.
Use without DataSource
DataGridView can work even without datasource. It's enough that you add some columns to DataGidView, then using datGridView1.Rows.Add add new rows to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With