Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnDelete.Click
'Declare Variables
Dim DeleteName As String
Dim Question As String
Dim intRow As Integer
'Get the row number of the current selection
intRow = dgvList.CurrentCell.RowIndex
'Get the FieldName of the proposed deletion
DeleteName = CStr(dgvList.Rows(intRow).Cells("LookUpName").Value)
Question = "Are you sure you want to delete " & DeleteName &
" from the list?"
DialogResult = MessageBox.Show(Question, "Confirm", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If DialogResult = DialogResult.No Then Exit Sub
'Delete Record
Delete_LookUpTable_Record(ToolDBName, TableName, FieldName,
ShortName(FieldName) & "Value", DeleteName)
dgvList.Rows.Clear()
PopulateFieldList(ToolDBName, FieldName, TableName)
End Sub
此代码运行后,包含dgvList的对话框会自动关闭。我也有按钮添加'和'编辑'重新填充dgvList后,对话框保持打开状态。
Private Sub btnEdit_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnEdit.Click
'Declare Variables
Dim NewName As String
Dim OldName As String
Dim RowUsed As String
Dim intRow As Integer
Dim NameCheckPass As Boolean
'Read the Used Column of Selected Rows
intRow = dgvList.CurrentCell.RowIndex
RowUsed = CStr(dgvList.Rows(intRow).Cells("Used").Value)
If RowUsed = "True" Then
DialogResult = MessageBox.Show("The value is used already. Confirm that " &
"you want to change the current text.", "Confirm",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning)
If DialogResult = DialogResult.No Then Exit Sub
End If
OldName = CStr(dgvList.Rows(intRow).Cells("LookUpName").Value)
Dim frmEdit As New frmNameInput
frmEdit.Text = "Edit Look Up Value"
frmEdit.lblName.Text = "Edit Look Up Value"
frmEdit.btnAdd.Text = "Update"
frmEdit.tbxName.Text = OldName
frmEdit.ShowDialog()
NewName = frmEdit.tbxName.Text
If NewName = OldName Then Exit Sub
Dim FieldSName = ShortName(FieldName)
'Check to see if Name is Unique on the DB Table
NameCheckPass = UniqueName(ToolDBName, TableName, FieldSName & "Value", NewName)
If NameCheckPass = False Then
MessageBox.Show("Name is not unique, please re-enter", "Not Unique",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
'Update DB Table
Update_LookUpTable_Record(ToolDBName, Create_TableName(FieldSName),
FieldName, FieldSName & "Value", NewName, FieldSName & "Value", OldName)
dgvList.Rows.Clear()
PopulateFieldList(ToolDBName, FieldName, Create_TableName(FieldName))
End Sub
所以这段代码很完美,不知道为什么btnDelete会关闭。
谢谢!!
答案 0 :(得分:0)
检查设计器中的btnDelete属性,如果将DialogResult设置为其他内容,则“无”'如果所述表格用作对话框并按下按钮,则表单将打开。