[英]how to disable button when its value stored in ms access database vb.net
當它的值存儲在 ms access 數據庫 vb 中時,按鈕將如何禁用。 net 示例 button1 的值為“101”,當單擊 button1 時,“101”值將顯示在文本框中,當我使用另一個按鈕將其存儲在 ms access 數據庫中時,button1 將被禁用
如果我理解正確,您有兩個按鈕和一個文本框。 Button1 在 TextBox 中顯示 Button1 上顯示的文本,然后 Button2 將文本框的內容存儲在 DB 中(不知何故),然后禁用 button1。 如果是這樣,試試這個:
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
如果您有多個按鈕,並且想根據 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.