7
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form2.Show()

    Form2.TextBox1.Text = dgv1.CurrentRow.Cells(0).Value.ToString
    Form2.TextBox2.Text = dgv1.CurrentRow.Cells(1).Value.ToString
    Form2.TextBox3.Text = dgv1.CurrentRow.Cells(2).Value.ToString
    Form2.TextBox4.Text = dgv1.CurrentRow.Cells(3).Value.ToString
    Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString
    Form2.TextBox6.Text = dgv1.CurrentRow.Cells(5).Value.ToString
    Form2.TextBox7.Text = dgv1.CurrentRow.Cells(6).Value.ToString

textbox5 は日付のみを表示する必要があるものですが、ボタンをクリックすると、テキストボックスに日付と時刻が表示されます。例: 12/01/12 午前 12:00。

テキストボックスに表示されないようにするにはどうすればよいですか?

4

5 に答える 5

8

CurrentCells(4).Value はオブジェクトなので、それを にキャストしてからDateTimeToShortDateString Method

Form2.TextBox5.Text = CType(dgv1.CurrentRow.Cells(4).Value, DateTime).ToShortDateString

またはDateTime.TryParse、変換が成功した場合に true を返す which を使用できます

Dim tempDate As Date
If DateTime.TryParse(CStr(dgv.CurrentRow.Cells(4).Value), tempDate) Then
    Form2.TextBox5.Text = tempDate.ToShortDateString
Else
    Form2.TextBox5.Text = "Invalid Date"
End If
于 2012-12-06T05:46:54.373 に答える
2

試す...

If dgv1.CurrentRow.Cells(4).Value IsNot Nothing
    Form2.TextBox5.Text = String.Format("{0:dd/mm/YYYY}", dgv1.CurrentRow.Cells(4).Value)
Else
    Form2.TextBox5.Text = ""
End If
于 2012-12-05T15:41:50.927 に答える
1

この行の .ToString を削除しました。

Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString

.ToString を削除すると、日付テキストボックスに短い日付が表示されるだけです

于 2012-12-06T11:11:44.427 に答える
1

日時フォーマット機能があります。これを確認してください http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.71).aspx

于 2012-12-05T15:42:07.027 に答える