如何通过询问用户他需要多少列和行来创建数据网格视图 [英] How Do I Create A Datagridview By Asking A User How Many Columns And Rows He Needs

查看:109
本文介绍了如何通过询问用户他需要多少列和行来创建数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个gridview,但首先我必须提示用户他需要多少列和行,并根据这些结果创建一个网格

i want to create a gridview, but first i must prompt the user how many colums and rows he needs and create a grid based on those results

推荐答案

for添加列

dataGridView1.Columns.Add(ID,ID);



和添加行

dataGridView1.Rows.Add(4);



用于循环并在n次执行这些语句

ex如果Colums = 4和行= 4

for(int i = 0; i< 4< i ++)> dataGridView1.Rows.Add(4);









简单定义DataTable dt添加你想要的列并添加行然后设置

dataGridView1 .DataSource = dt;
for adding columns
dataGridView1.Columns.Add("ID","ID");

and for adding Row
dataGridView1.Rows.Add(4);

use for loop and execute these statements at n times
ex if Colums=4 and rows=4
for(int i=0;i<4<i++)>dataGridView1.Rows.Add(4);


OR

Simple define DataTable dt add columns u wants and add rows then set
dataGridView1.DataSource=dt;


如果你想在datagridview中动态添加行和列(正如你在问题标题中提到的那样),你可以使用获取的ColumnCount和RowCount属性轻松完成或设置DataGridView中显示的列数和行数。




If you want to add rows and columns dynamically in datagridview (As you mention in your question headings), you can do it very easily with ColumnCount and RowCount property which Gets or sets the number of columns and rows displayed in the DataGridView.


dataGridView1.ColumnCount = columnCount;
           dataGridView1.RowCount = rowCount;







但是如果你想添加行和列动态地在gridview中(正如你在问题中提到的)在Web应用程序中它会有所不同。为此,你可以按照下面的链接。





如何在网格视图中动态创建列 [ ^ ]


这篇关于如何通过询问用户他需要多少列和行来创建数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆