0
每次我想编辑数据时,DateTimePicker会忽略或不接受DataGridView的值。 我试图调试它,但它不起作用,DateTimePicker保持不变,它不会更改DataGridView的值基。DateTimePicker不接受来自DataGridView的日期值到编辑表格
下面的代码:
代码以打开编辑表单:
Dim editData As New AddData
Private Sub editForm()
editData.Options = "EditData"
editData.load_leasee(leasee_id)
editData.ShowDialog()
End Sub
Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditToolStripMenuItem.Click
editForm()
End Sub
代码为CellClickValue功能和DataGridView1_CellClick:
Private Sub CellClickValue(ByVal selectedRow As DataGridViewRow)
selectedRow = DataGridView1.Rows(index)
editData.ExpiryDate = Format(selectedRow.Cells(15).Value, "yyyy-MM-dd").ToString() 'Expiry Date
End Sub
Dim selectedRow As DataGridViewRow
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
'Dim index As Integer
index = e.RowIndex
Console.WriteLine("index: " & index)
If index > -1 Then
CellClickValue(selectedRow)
Else
'Button2_EditForm.Enabled = False
disableButton_InHome()
End If
End Sub
代码编辑数据表格。该错误是在这里:
Public Property Options As String
Public Property ExpiryDate As String
Public Sub showInputs()
Try
'
DateTimePicker2_ExpDt.Value = ExpiryDate.ToString() 'Ignores the value
DateTimePicker2_ExpDt.Text = ExpiryDate.ToString() 'Ignores the value
'
TextBox4_ExpDt.Text = ExpiryDate 'Accepts the value
Catch ex As Exception
TextBox4_ExpDt.Text = ""
DateTimePicker2_ExpDt.Text = ""
End Try
End Sub
Private Sub loadOptions()
Console.WriteLine("Options: " & Options)
If Options = "EditData" Then
Me.Text = "Edit Data"
showInputs()
End If
End Sub
它的工作,但是当我再次编辑时,DateTimePicker再次重置。 –
我发现每次在关闭表单后清除或重置DateTimePicker时,它都不起作用。 –
@GuideMe:在'DateTime.TryParse'行上放置一个断点并告诉我'ExpiryDate'的值是多少。 –