[英]Can I use DataGridView without using database data?
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. 我有一个客户端 - 服务器程序,服务器收到[进程ID,主机名,应用程序名称,文件路径],我想把它们放在一个表中。 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?
DataGridView是否适用于即使它们不在数据库中还是有其他选项?
Thanks. 谢谢。
The short answer is Yes. 简短的回答是肯定的。
List<T>
as DataSource
List<T>
作为DataSource
DataTable
as DataSource
(DataTable not related to db) DataTable
作为DataSource
(DataTable与db无关) DataSource
and only defining columns and adding rows DataSource
情况下使用它,只定义列和添加行 Use with List<T>
as DataSource
for example: 例如,使用
List<T>
作为DataSource
:
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. 结果将是一个带有2列(Property1,property2)和3行的dataGridView。
In above example, DataClass
is a class like the following: 在上面的示例中,
DataClass
是一个类如下的类:
public class DataClass { public int Property1 {get; public class DataClass {public int Property1 {get; set;} public string Property2 {get;
set;} public string Property2 {get; set;} }
设置;}}
For more advance scenarios you can use DataSource window to add new DataSource to your project. 对于更多高级方案,您可以使用DataSource窗口将新的DataSource添加到项目中。 You can add Object datasource as well.
您也可以添加Object数据源。
use with a DataTable
as DataSource
与
DataTable
一起使用作为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. 您可以创建一个
DataTable
,并使用添加列到它dataTable.Columns.Add
然后使用添加行dataTable.Rows.Add
,然后将其设置为DataSource
网格。
Use without DataSource
不使用
DataSource
DataGridView can work even without datasource. 即使没有数据源,DataGridView也可以工作。 It's enough that you add some columns to DataGidView, then using
datGridView1.Rows.Add
add new rows to it. 向DataGidView添加一些列就足够了,然后使用
datGridView1.Rows.Add
向其中添加新行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.