禁用按钮,直到选中了“两列datagridview"复选框. [英] Disabling a button until both column datagridview checkbox is checked.

查看:47
本文介绍了禁用按钮,直到选中了“两列datagridview"复选框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的.我有2个DatagridViewChecKboxColumn.我想发生的是一个(Submit)按钮将被禁用,直到checkbox2被选中为止.如果我的复选框是DataGridViewCheckboxColumn,该怎么办?我将执行哪个循环,因为我可能会选中最后一个复选框?任何的想法?

CheckboxColumn1是父",而CheckboxColumn2是子",它们彼此相关.要求父母必须至少有一个孩子,这意味着它可以是一个对多©的P(P)或对一个©的P(P).如果用户不满足上述要求,则系统不应允许他将所选记录插入数据库.这就是为什么我决定禁用按钮的原因,除非用户选中了两个复选框.这意味着,如果用户仅选中子级"列中的复选框,则该按钮将保持禁用状态,与父级"复选框列相同.我所说的按钮是所谓的合并按钮".

我尽力清楚地解释了这一点.如果您想澄清一些问题,您仍然可以要求更多.这是我需要解决的最后一件事.请对我耐心点.

我将在此处发布一些代码.

我试过了:


Ok. I have 2 DatagridViewChecKboxColumn. What I want to happen is that a (Submit)button will be disabled until the checkbox2 will be checked. How will I do this if my checkboxes are DataGridViewCheckboxColumn? What loop will I do,because there''s a possibility that I''ll be checking the last checkbox? Any idea?

CheckboxColumn1 is "Parent" and CheckboxColumn2 is "Child", they are related to each other. It''s a requirement that the Parent has to have at least 1 Child meaning it can be One(P) is to Many© or One(P) is to One©. If the user didn''t meet the said requirement, the system should not allow him to insert the selected records to the database. That''s why I''ve decided to Disable the button unless the user checked the two checkboxcolumn. Meaning if the user only checked the checkbox/es in the Child column, the button will remain disabled, same concept with the Parent checkboxcolumn. The button that I''m talking about is what I call "Consolidate Button".

I tried my best to explain it clearly. You can still ask for more if you want to clarify something. This is the last thing I need to fix. Please be patient with me.

I''ll post some of my codes here.

I tried this:


Private Function HasParentAndChild() As Boolean
        Dim result As Boolean = False
        Dim hasParentCode As Boolean = False
        Dim hasChildCode As Boolean = False
        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            If CBool(Me.DataGridView1.Rows(i).Cells(0).Value) = True Then
                hasParentCode = True
            ElseIf CBool(Me.DataGridView1.Rows(i).Cells(1).Value) = True Then
                hasChildCode = True
            End If
            If hasParentCode And hasChildCode Then
                result = True
                Exit For
            End If
            ' MsgBox(i & " " & hasParentCode & " " & hasChildCode, vbOKOnly)
        Next
        Return result
    End Function



试图将其放在所有与CELL相关的事件中.



Tried to put this in all CELL related EVENTS.

If HasParentAndChild() Then
            btnConso.Enabled = True
        Else
            btnConso.Enabled = False
        End If

Omfg.我对这个datagridview感到非常绝望. T_T.一直在尝试学习如何控制datagridview,但这让我头疼.无论如何,我希望有人可以在这里解决我的问题.

我试过了,但还是没用.它确实禁用了按钮,但是在随机单击/检查中意味着在任何复选框中单击3次后,按钮将被禁用,并在单击几次后再次启用.不知道是什么问题.试图调试,但我不明白. Im stcked.

Omfg. I am so desperate with this datagridview. T_T. Been trying to learn how to control datagridview but it''s giving me a headache. Anyway, I hope someone could help me with my problem here.

I tried this, but still not working. It does disable the button but in random clicks/checks meaning after 3 clicks in anycheckboxes the button will be disabled and be enabled again after how many clicks. Dont know what the problem is. Tried to debug but I dont get it. Im stcked.

推荐答案

首先要看的是如何启动检查:是从一个事件开始的,如果是的话,是哪个事件的?
我将使用DataGridView.CellValidating事件并从那里开始.
The first thing to look at is how you are initiating the check: Is it from an event, and if so, which one?
I would use the DataGridView.CellValidating Event and start from there.


这篇关于禁用按钮,直到选中了“两列datagridview"复选框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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