如何使用'x'和'y'的值填充datagridview [英] How do I populate datagridview with values of 'x' and 'y'
问题描述
大家好,我正在通过自学vb编程并提出问题
说我有一个等式...简单的y = 2x + 1
按下按钮后,我希望datagridview填充2列
x列,值为0到5,增量为0.2
y column with the equation of methods with x values
开始时遇到一点麻烦
任何提示都将不胜感激!
最简单的方法是绑定 DataTable [ ^ ]对象 DataGridView [ ^ ]控制。
Dim dt As DataTable = 新 DataTable()
dt.Columns.Add(新 DataColumn( x,Type。 GetType ( System.Double)))
dt.Columns.Add(新 DataColumn( y,Type。 GetType ( System.Double)))
对于 x 作为 Double = 0 。 0 5 步骤 0 。 2
dt.Rows.Add(新 对象(){x,2 * x + 1})
下一步
DataGridView1.DataSource = dt
注意:不要忘记设置 DataGridView.AutoGenerateColumns属性 [ ^ ]到True
!
如需了解更多信息,请参阅:
DataGridView.DataSource属性 [ ^ ]
如何:将数据绑定到Windows窗体DataGridView控件 [ ^ ]
如何:在数据绑定的Windows窗体DataGridView控件中自动生成列 [ ^ ]
Hello all, i'm working through teaching myself vb programming and have a question
Say I have an equation...something simple y = 2x + 1
Upon hitting a button, I want datagridview to populate 2 columns
x column with values from 0 to 5 in increments of 0.2
y column with results of the equation with those x values
Just having a little trouble getting started
Any hints would be greatly appreciated!
The simplest way is to bind DataTable[^] object with DataGridView[^] control.
Dim dt As DataTable = New DataTable() dt.Columns.Add(New DataColumn("x", Type.GetType("System.Double"))) dt.Columns.Add(New DataColumn("y", Type.GetType("System.Double"))) For x As Double = 0.0 To 5 Step 0.2 dt.Rows.Add(New Object(){x, 2*x+1}) Next DataGridView1.DataSource = dt
Note: Do not forget to set DataGridView.AutoGenerateColumns Property [^] toTrue
!
For further information, please see:
DataGridView.DataSource Property [^]
How to: Bind Data to the Windows Forms DataGridView Control[^]
How to: Autogenerate Columns in a Data-Bound Windows Forms DataGridView Control[^]
这篇关于如何使用'x'和'y'的值填充datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!