我使用VS 2008和VB.NET作为语言。我有两个网格。在一个网格中,ii具有用户的数据。例如手机号码,电子邮件和其他信息。在第二个网格中,我已经添加了一些警报。
我需要在警报gridview中的每一行附加两个复选框列。单击该复选框,将执行特定的数据库操作。
目前,我在datagridview中添加了复选框,但我无法检查/取消选中它们。
请帮我解决检查/取消选中问题,并提示我执行复选框点击的数据库操作。
这就是我在datagridview
中添加复选框的方法Dim email As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn(True)
Dim sms As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn(True)
email.HeaderText = "Email"
email.ReadOnly = False
sms.HeaderText = "SMS"
sms.ReadOnly = False
UserAlarmDataGridView.Columns.Add(email)
UserAlarmDataGridView.Columns.Add(sms)
我尝试将列的readonly属性设置为false,但它不起作用。
答案 0 :(得分:0)
检查以下代码
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim AlarmColumn1 As New DataGridViewCheckBoxColumn(True)
Dim AlarmColumn2 As New DataGridViewCheckBoxColumn(True)
AlarmColumn1.Name = "Alarm1"
AlarmColumn1.HeaderText = "Email"
AlarmColumn1.ReadOnly = False
AlarmColumn2.Name = "Alarm2"
AlarmColumn2.HeaderText = "SMS"
AlarmColumn2.ReadOnly = False
UserAlarmDataGridView.Columns.Add(AlarmColumn1)
UserAlarmDataGridView.Columns.Add(AlarmColumn2)
UserAlarmDataGridView.ReadOnly = False
End Sub
基于CheckBox单击进行数据库操作,请使用以下
Private Sub UserAlarmDataGridView_CellContentClick(sender As Object, _
e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UserAlarmDataGridView.CellContentClick
Dim ColumnName1 As String = UserAlarmDataGridView.Columns(e.ColumnIndex).Name
If ColumnName1 = "Alarm1" Or ColumnName1 = "Alarm2" Then
Dim CellCheckBox1 As DataGridViewCheckBoxCell = _
CType(UserAlarmDataGridView.Rows(e.RowIndex).Cells(ColumnName1), DataGridViewCheckBoxCell)
Dim CellCheckBoxState1 As String = CellCheckBox1.EditingCellFormattedValue.ToString
MsgBox("Row = " & CellCheckBox1.RowIndex & vbCrLf & _
"Column = " & CellCheckBox1.ColumnIndex & vbCrLf & _
"State = " & CellCheckBoxState1)
End If
End Sub
答案 1 :(得分:0)
捕获复选框状态值的更好方法....
micInputStream.on('data', function(data) {
console.log("Recieved Input Stream: " + data.length);
});