重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
将二位数组或册转成DataTable,网上找的不返和知道成不成
创新互联公司是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,成都小程序开发,10多年建站对成都高空作业车租赁等多个行业,拥有多年的网站制作经验。
public static DataTable ConvertToDataTable(string[,] arr)
{
DataTable dataSouce = new DataTable();
for (int i = 0; i arr.GetLength(1); i++)
{
DataColumn newColumn = new DataColumn(i.ToString(), arr[0, 0].GetType());
dataSouce.Columns.Add(newColumn);
}
for (int i = 0; i arr.GetLength(0); i++)
{
DataRow newRow = dataSouce.NewRow();
for (int j = 0; j 衫世宏 arr.GetLength(1); j++)
{
newRow[j.ToString()] = arr[i, j];
}
dataSouce.Rows.Add(newRow);
}
return dataSouce;
}
下面这段代码完成,在窗体上用语句添加2个 GroupBox控件,且在每个冲孝GroupBox控件中添加4个 RadioButton 控件。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
'添加2个GroupBox
Dim MyGroupBox(2) As GroupBox
For i = 1 To 2
'将一个GroupBox控件加入到Form上
MyGroupBox(i) = New GroupBox
Me.Controls.Add(MyGroupBox(i))
'设置该GroupBox控件的属性
MyGroupBox(i).Height = 240
MyGroupBox(i).Width = 600
MyGroupBox(i).Top = (i - 1) * (240 + 20) + 20
MyGroupBox(i).Left = 20
'修改新加入控件的Text值
MyGroupBox(i).Text = "GroupBox" CStr(i)
Next
'每个GroupBox中添加4个派判吵单选按钮
Dim MyRadioButton1(4) As RadioButton
Dim MyRadioButton2(4) As RadioButton
For i = 1 To 4
MyRadioButton1(i) = New RadioButton
Me.Controls.Add(MyRadioButton1(i))
MyRadioButton1(i).Parent = MyGroupBox(1)
'设置该GroupBox控尘侍件的属性
MyRadioButton1(i).Height = 20
MyRadioButton1(i).Width = 120
MyRadioButton1(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton1(i).Left = 20
'修改新加入控件的Text值
MyRadioButton1(i).Text = "RadioButton1_" CStr(i)
Next
For i = 1 To 4
MyRadioButton2(i) = New RadioButton
Me.Controls.Add(MyRadioButton2(i))
MyRadioButton2(i).Parent = MyGroupBox(2)
'设置该GroupBox控件的属性
MyRadioButton2(i).Height = 20
MyRadioButton2(i).Width = 120
MyRadioButton2(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton2(i).Left = 20
'修改新加入控件的Text值
MyRadioButton2(i).Text = "RadioButton2_" CStr(i)
Next
End Sub
datagrid不行,因为datagrid绑定数据库梁核知,因此不能添加一个附加行。即使在SQL命令中通过union方式进行统计后显示,但又会导致datagrid不能新增。解决办法有2个:1、用MSFlexGrid;2、自己写一个用户控件,大概意思就是里面有2个datagrid,一个大的,专门显示记录,一个小的,不要标题行,专门显橡消示合计数;在里面增加写代码使它们水平氏握同步滚动。