简体   繁体   English

当按钮的值存储在 ms 访问数据库 vb.net 中时如何禁用按钮

[英]how to disable button when its value stored in ms access database vb.net

how button will disable when it's value stored in ms access database vb.当它的值存储在 ms access 数据库 vb 中时,按钮将如何禁用。 net Example button1 value is "101" and when the button1 is clicked the "101" value will display in textbox and when i stored it in the ms access database by using another button, the button1 one will be disabled net 示例 button1 的值为“101”,当单击 button1 时,“101”值将显示在文本框中,当我使用另一个按钮将其存储在 ms access 数据库中时,button1 将被禁用

If I understand correctly you have two buttons and a textbox.如果我理解正确,您有两个按钮和一个文本框。 Button1 displays the text displayed on Button1 in the TextBox and then Button2 stores the content of the textbox in the DB (somehow) then disables button1. Button1 在 TextBox 中显示 Button1 上显示的文本,然后 Button2 将文本框的内容存储在 DB 中(不知何故),然后禁用 button1。 If so, try this:如果是这样,试试这个:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.Text = Button1.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim DBValue As String = TextBox1.Text
    'Store DBValue in DB
    Button1.Enabled = False
End Sub

If you have multiple buttons and want to find which button was pressed based on the value in textbox1, try this:如果您有多个按钮,并且想根据 textbox1 中的值查找按下了哪个按钮,请尝试以下操作:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    For Each ctrl As Control In Me.Controls
        If (ctrl.GetType() Is GetType(Button)) Then
            Dim btn As Button = ctrl
            If btn.Text = TextBox1.Text Then
                DBValue = TextBox1.Text
                'Store DBValue in DB
                btn.Enabled = False
                Exit For
            End If
        End If
    Next
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM