如何将datagridview复选框列状态添加到布尔数组 [英] How to add datagridview check box column states to boolean array
本文介绍了如何将datagridview复选框列状态添加到布尔数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有相同形式的datagridview,有些是复选框和组合框列
i尝试将那些列数据(例如复选框状态)设置为布尔数组,将组合框文本设置为字符串数组但是这么多错误按摩来了......有谁知道泰铢怎么样??
我的目的是那些数组会写入文本文件... < br $> b $ b
我尝试过:
I have few datagridview in same form some are having checkbox and combo box columns
i try to get those column data such as checkbox states to boolean array and combobox text to string array but so many error massages is came.. anyone know How do thais..?
My Purpose is those array will write to text file...
What I have tried:
Public Class Form1
'// I have insert data grid. its first column is check box and second columns is check box
'// I want to add to array each row
'// And i have few data grid in same form
Dim data() As String = {}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'// For first row
For a As Integer = 0 To 5
data(a) = DataGridView1.Rows(a).Cells(0).Value.ToString
TextBox1.AppendText(data(a))
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Rows.Add(10)
End Sub
End Class
推荐答案
CheckState将返回 Checked,Unchecked,Indeterminate 。但是你需要一个布尔值,所以你要查找Checked
属性,而不是CheckState
属性。
CheckState will return Checked, Unchecked, Indeterminate. But you need a Boolean value, so you look for theChecked
Property, not theCheckState
Property.
For a = 1 To 5
Dim bool As Boolean
'assuming Cells(x) is a CheckBox
bool = DataGridView1.Rows(a).Cells(0).Checked
data(a-1) = bool.ToString
Next
End Sub
这篇关于如何将datagridview复选框列状态添加到布尔数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文