如何控制DataGridView复选框是对还是错? [英] How Can I Control DataGridView Checkbox True Or False ?

查看:73
本文介绍了如何控制DataGridView复选框是对还是错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览次数:1
大小:20.4 KB"border ="0"src ="http://www.vbforums.com/attachment.php ?attachmentid = 157737&d = 1522419484"title ="名称:RecordEmpty.jpg
浏览次数:1
大小:20.4 KB"style ="border:0px; max-width:100%;颜色:#333333; font-family:Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif; font-size:13px; background-color:#fafafa">



浏览次数:1
大小:20.4 KB" border ="0"src ="http://www.vbforums.com/attachment.php?attachmentid=157739&d=1522419500"title ="姓名:RecordTrue.jpg
浏览量:1
尺寸:20.4 KB"style ="border:0px; max-width:100%; color:#333333; font-family:Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif; font-size:13px; backgroun d-color:#fafafa">



我只是想用Checkbox过滤所选行的DataGridView记录。





在这里点代码就像这样......



如果选择了任何记录(Row),则选择记录按钮Enabled = False



如果选择了至少1个记录(行),则选择了Rocords Button Enabled = True。



这是下面的代码。





Private Sub SecimBtn_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理SecimBtn.Click

For i As Integer = DgV.Rows.Count() - 1 To 0 Step -1



Dim Sil As Boolean

Sil = DgV.Rows(i).Cells(0).Value



'''''如果选中复选框单元格

如果Sil = False然后 





Dim row As DataGridViewRow

row = DgV.Rows(i)

DgV.Rows.Remove(row)



结束如果



下一页





For x As Integer = 0 To DgV.RowCount - 1



DgV.Rows(x).Cells(0).Value = False



下一页





End Sub

Name:  RecordEmpty.jpg
Views: 1
Size:  20.4 KB

Name:  RecordTrue.jpg
Views: 1
Size:  20.4 KB

I just want to to filter DataGridView Records by Selected Rows with Checkbox.


in tihs point code work as this....

if any record (Row) selected then Selected Records Button Enabled = False

if at least 1 record (Row) selected then Selected Rocords Button Enabled = True.

Here is the Code at below.


Private Sub SecimBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SecimBtn.Click
For i As Integer = DgV.Rows.Count() - 1 To 0 Step -1

Dim Sil As Boolean
Sil = DgV.Rows(i).Cells(0).Value

' ''''if the checkbox cell is checked
If Sil = False Then 


Dim row As DataGridViewRow
row = DgV.Rows(i)
DgV.Rows.Remove(row)

End If

Next


For x As Integer = 0 To DgV.RowCount - 1

DgV.Rows(x).Cells(0).Value = False

Next


End Sub

推荐答案





如何我可以控制DataGridView复选框是真还是假?
$
您可以在DataGridView的第一行和最后一行循环,并检查是否选中[Select](CheckBoxColumn)。


代码就是这样的。

Hi,

How Can I Control DataGridView Checkbox True Or False?
You can loop within the first row and the last row in the DataGridView, and check if [Select] (CheckBoxColumn) is checked or not.
Code would be like this.

SecimBtn.Enabled = False For myRow As Integer = 0 To DgV.Rows.Count - 1

If(DgV(0,myRow).Value = True)然后
SecimBtn.Enabled = True
退出
结束如果
下一步

If (DgV(0, myRow).Value = True) Then SecimBtn.Enabled = True Exit For End If Next


问候,

Regards,


这篇关于如何控制DataGridView复选框是对还是错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆