到目前为止,我已编写代码以保持Save& Update按钮被禁用,直到用户填充Groupbox中的所有必填字段(Textboxes& Comboboxes),但我还希望Save& Update按钮保持禁用状态,直到用户解决了所有可用错误例如Book_Name的形式不应超过50个字符!
如果有人帮助我,我真的很感激!
下面是我试图这样做的代码,但我不知道上面提到了什么代码:
Private Sub ValidateInputs(ByVal Sender As Object, ByVal e As EventArgs)
Dim ctrl As Control
Dim strErrorList As String
strErrorList = ""
For Each ctrl In Me.Controls
If Len(ErrorProvider1.GetError(ctrl)) > 0 Then
strErrorList += ErrorProvider1.GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next
If Len(strErrorList) = 0 Then
' Process stuff if no errors
btnsave.Enabled = Not GroupBox1.Controls.OfType(Of TextBox).Any(Function(t) t.Text = String.Empty) And _
Not (cboStaff_id.Text = String.Empty OrElse cboPub_id.Text = String.Empty OrElse cboSub_Code.Text = String.Empty _
OrElse DateTimePicker1.Text = " ")
btnSaveUpdate.Enabled = Not GroupBox1.Controls.OfType(Of ComboBox).Any(Function(cbo) cbo.Text = String.Empty) And _
Not (txtbook_name.Text = String.Empty OrElse txtauthor.Text = String.Empty OrElse txtprice.Text = String.Empty _
OrElse txtrack_no.Text = String.Empty OrElse TxtNo_of_Books.Text = String.Empty OrElse txtvol_no.Text = String.Empty OrElse DateTimePicker1.Text = " ")
btndelete.Enabled = Not (cboISBN.Text = String.Empty)
Else
btnsave.Enabled = False
btnSaveUpdate.Enabled = False
MessageBox.Show(strErrorList, "List Of Errors")
End If
End Sub
答案 0 :(得分:0)
使用错误提供程序或创建自己的错误提供程序,执行您和ISBN文本框所需的任务说放置MaxLength = 13它将执行任务而不使用任何错误提供程序或验证程序,对于电子邮件的电话号码使用屏蔽文本框,或者如果您只想接受该文本框中的数字,则处理文本框的文本更改事件
答案 1 :(得分:0)
自从我4天前提出这个问题并且没有人提供解决问题的答案后,我研究了&重新检查我的代码并找到解决我问题的方法!
所以我要解释每一点,以澄清我所做的事情。
class A(models.Model):
x = models.IntegerField()
def copy(self):
obj = self
obj.pk = None
obj.save()
return obj
class B(A):
y = models.IntegerField()
def copy(self):
# this method is what I am confused about
new_parent = super(B, self).copy() # not sure about this
obj = self
obj.pk = None
# how to set obj's parent model to 'new_parent'
obj.save()
return obj
希望这会有所帮助......