Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
here my code :

VB
'for clear the date value 
Sub clear()
        dtpDOJ.Text = " "
End sub

'for return value to datetime picker when datagridview is clicked
 Private Sub dgvdatakaryawan_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvdatakaryawan.CellContentClick
 Dim i As Integer
        Dim n As Integer = dgvdatakaryawan.Rows.Count
        If n = 0 Then
            Call clear()
        Else
            Try
                i = dgvdatakaryawan.CurrentRow.Index
                dtpDOJ.Text = dgvdatakaryawan.Item(1, i).Value
            Catch ex As Exception

            End Try
        End If
   End Sub

'this is property of datetimepicker
Private Sub dtpDOJ_ValueChanged_1(ByVal sender As System.Object, ByVal e As      System.EventArgs) Handles dtpDOJ.ValueChanged
        Me.dtpDOJ.Format = Windows.Forms.DateTimePickerFormat.Custom
        Me.dtpDOJ.CustomFormat = "dd MMMM yyyy"
    End Sub
[^]
Posted
Updated 10-Jun-15 17:43pm
v2
Comments
Ralf Meier 11-Jun-15 0:45am    
... and what is your problem ?
Please explain exactly ...
Why don't you work with the "DataGridViewCellEventArgs" ?
Akbar Giffary 11-Jun-15 0:59am    
my problem is when i click datagridview with cell value is empty, the datetimepicker still showing value and not empty
Ralf Meier 11-Jun-15 3:42am    
The DateTimePicker does not have the possibility of no value (like a TextBox for example).
The Value-Property must allways have a assign between MinDate and MaxDate.
Now : what do you want to have else ...?
Akbar Giffary 11-Jun-15 5:10am    
is there any solution to make textbox with date format dd-MMM-yyyy ?
or other solution to insert date to datagrid which can return backto textbox or datetime when just clicked
Ralf Meier 11-Jun-15 6:47am    
All jobs which could be described are programmable ...
Perhaps you tell me something additional about your plan ... in the moment I'm unable to make some good suggestions :(

1 solution

OK ... this is my idea :
I would create a Dialog which is called by your selected functions.
To this Dialog you give the relevant Information(s) by Properties.
Inside the Dialog you work with the elements (DateTimePicker, TextBox, Combobox etc.) like you do it in the moment.
To leave the Dialog you have the Buttons "Abort" and "OK" which gave a DialogResult to the calling method. Now the calling method can decide, if you wish to take the changes or not.
Inside the Dialog (perhaps with the Properties) you are able to deliver an empty String to the caller of the Dialog.

Do you understand what I mean ...?
Could you follow me or do you need further Information ?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900