多个复选框值进入datagridview single coloum [英] Multiple checkbox value into datagridview single coloum
问题描述
如果要检查要合并的数据并将其插入到datagridview单列中,我正在尝试允许特定的复选框。
表单正在添加列如下;
I'm trying to allow specific checkbox's if checked for the data to be merged and to be inserted into the datagridview single column.
The form is adding column as follows;
table.Columns.Add("Drinks", Type.GetType("System.Int32"))
然后
复选框1 =可乐
复选框2 =百事可乐复选框3 =芬达
公共类具有以下代码;
Then
Checkbox 1 = Coke
Checkbox 2 = Pepsi Checkbox 3 = Fanta
Public Class has the following code;
Dim Drinks As String
每个复选框都有以下代码及其文字;
Drinks =可乐
生成按钮信息如下;
Each of the checkbox has the following codes along with their text;
Drinks = "Coke"
The button to generate the information is as follows;
table.Rows.Add(Drinks.ToString)
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
DataGridView1.RowTemplate.Height = 100
DataGridView1.AllowUserToAddRows = False
DataGridView1.DataSource = table
因此,如果有人选择'Checkbox1& Checkbox2'我如何获得datagridview coloum'Drinks'来显示可乐和放大器百事可乐?
我的尝试:
N / A i没有尝试任何东西,因为我找不到类似的线程
Therefore if someone selects 'Checkbox1 & Checkbox2' how can i get datagridview coloum 'Drinks' to show coke & pepsi?
What I have tried:
N/A i haven't tried anything as i can't find similar thread
推荐答案
请注意,您的列只能接受整数值,因为这行:
Note that your column can accept only integer value, because of this line:
table.Columns.Add("Drinks", Type.GetType("System.Int32"))
您正在尝试添加字符串(这是错误的!):
And you're trying to add string (which is wrong!):
Dim Drinks As String
Drinks = "Coke"
table.Rows.Add(Drinks.ToString) 'Note: ToString() method is redundant
如果要添加整数值,则必须检查Checkbox是否已检查 [ ^ ],然后添加一行数据表。
假设每种饮料都有其数值,你可以使用这样的东西:
If you want to add integer value, you have to check if Checkbox is Checked[^], then to add a row into datatable.
Assuming that each drink has its numeric value, you can use something like this:
'Coke = 1
If CheckBox1.Checked Then table.Rows.Add(New Object(){1})
这篇关于多个复选框值进入datagridview single coloum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!