首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >取消后刷新表单

取消后刷新表单
EN

Stack Overflow用户
提问于 2020-07-20 16:35:08
回答 1查看 63关注 0票数 0

在我的windows窗体中,我添加了一个用于输入新记录的按钮,当该按钮被选中时,按钮文本将变为取消,焦点将移动到第一个输入字段。但是如果我在没有输入任何数据的情况下单击cancel,当我按下next record时,焦点不会被移除,那么焦点就会被移除&我可以再次按add .and record按钮。请帮助我如何解决这个.below是我的代码

代码语言:javascript
复制
    Private Sub AddnewButton_Click(sender As Object, e As EventArgs) Handles AddnewButton.Click
    'MsgBox("you preseed add new button")
    Try
        With AddnewButton
            If .Text = "Add New Record" Then
                MSdiesBindingSource.AddNew()
                .Text = "Cancel"
            Else
                RefreshData()
                .Text = "Add New Record"
            End If

        End With
        With Size_in_mgTextBox
            If (.CanSelect) Then
                .Text = String.Empty
                .Select()
            End If
        End With

        IsAddNewRecordInProgress = Convert.ToBoolean(AddnewButton.Text = "Cancel")


    Catch ex As Exception
        MsgBox("An error occured: " & ex.Message.ToString().ToString(),
              MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Add new Record Failed")
    End Try
End Sub
    Private Sub RefreshData()
    Try
        'Me.MSdiesBindingSource.Filter = Nothing
        MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
        MSdiesBindingSource.RemoveFilter()
    Catch ex As Exception
        MsgBox("Refresh Data Error!")
    End Try


End Sub

代码语言:javascript
复制
SELECT        ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns],[Condition of DIE-1], [Condition of DIE-2], [Condition of DIE-3], [Condition of DIE-4], [Condition of DIE-5],[Condition of DIE-6],[Condition of DIE-7], Observations, Inspector

来自MSdies

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-23 16:15:56

代码语言:javascript
复制
But if i click cancel without entering any data , the focus is not getting removed

为了从'Size_ In _mgTextBox‘中移除焦点,你可以对你的代码做一些修改:

代码语言:javascript
复制
    With Size_in_mgTextBox
        If (.CanSelect) Then
            .Select()
        End If
    End With
    With AddnewButton
        If .Text = "Add New Record" Then
            bindingSource.AddNew()
            .Text = "Cancel"
        Else
            RefreshData()
            .Text = "Add New Record"
        End If
    End With

    Size_in_mgTextBox.Text = String.Empty

然后将以下代码添加到“RefreshData”方法中:Me.ActiveControl = Nothing

代码语言:javascript
复制
Private Sub RefreshData()
    If Size_in_mgTextBox.Text.Trim = "" Then
        Me.ActiveControl = Nothing
    Else
        '...
    End If
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62991536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档