Calendar Control and DataGrid

Using the calendar control, how can I double click a field with the datagrid and update that field with the value from a calendar control?
vmoralesAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
I hope that you will appreciate to its value!

On a form, place a ADO Data control, a Datagrid control and a MonthView control without changing any properties. Then copy this code:

Option Explicit

Private Sub DataGrid1_DblClick()
    With DataGrid1
        If .Columns(.Col).Caption = "OrderDate" Then
            MonthView1.Left = .Left + .Columns(.Col).Left
            MonthView1.Top = .Top + ((.Row + 2) * .RowHeight)
            MonthView1.Visible = True
            MonthView1.SetFocus
        End If
    End With
End Sub

Private Sub Form_Load()
    'Hide the calendar
    MonthView1.Visible = False
   
    'Set the datasource
    With Adodc1
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\Nwind2000.mdb;Persist Security Info=False"
        .CommandType = adCmdText
        .RecordSource = "SELECT OrderId, CustomerID, OrderDate, EmployeeID FROM Orders"
        .Refresh
    End With
   
    'Set the Grid
    With DataGrid1
        Set .DataSource = Adodc1.Recordset
        .Columns("OrderDate").Locked = True
        .RowHeight = 200
    End With
End Sub

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    DataGrid1.Text = MonthView1.Value
    MonthView1.Visible = False
End Sub

Private Sub MonthView1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        MonthView1.Visible = False
    End If
End Sub
0
 
Éric MoreauSenior .Net ConsultantCommented:
I have this code that display a listbox in a datagrid.

It can surely be easily modified to display the calendar control.

How do i correctly allign the listbox to show a dropdown in the dbgrid (ButtonClick event)? It is possible to do show it using the Rowheight property but alligning it presicely is a problem. Any suggestions?

===============================
 
This example uses a list box, but you can replace the name of the list control with a combobox to achieve the same result :

Replace grdCensus with your grid control name.

First in the click command of the list/combo control :

Private Sub DBList1_Click()

grdCensus.Col = 2 'replace with the column you need
grdCensus.Text = DBList1.Text
grdCensus.SetFocus
grdCensus.Col = 3 'the next col you want to have focus
DBList1.Visible = False

End Sub

In the RowColChange event of your grid :

With grdCensus
'in the code below replace 2 with your column #
    If .Col = 2 And .Text = "" Then
       DBList1.Left = .Left + .Columns(2).Left
       DBList1.Top = .Top + (.Row * .RowHeight) + SSTab1.Top
'the line below makes sure the list isn't being shown off
'the bottom of the screen. You'll need to adjust the value
'3600 as needed depending on your forms size and position
       If DBList1.Top > 3600 Then DBList1.Top = 3600
       DBList1.ZOrder 0
       DBList1.Visible = True
       DBList1.SetFocus
    Else
       DBList1.Visible = False
    End If
end with

 
0
 
vmoralesAuthor Commented:
I am confused, did you intend to respond to some other question?

If your response is intended for my question, let me know so that I clarify my question.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Éric MoreauSenior .Net ConsultantCommented:
Don't you want to make a calendar control appear when you click a grid cell?
0
 
vmoralesAuthor Commented:
That would be fine I suppose, but what I was after was the ability to double-click a cell and it insert a date. With the DataGrid it does not seem to have any properties that would allow me to do that. I have also tried the MSHFlexGrid control and I can get it to work here but it just diplays the date and does not update the record.

The code you displayed looked as though it used tabstrip controls.

P.S.

I am very new at this.

Thanks,
0
 
vmoralesAuthor Commented:
My main problem with this whole thing is that I can't seem to find a way to determine what cell location I am in so that I can automatically place a date value in the cell.

Unlike the some of the flexgrid controls the datagrid does not have a textmatrix property.
0
 
vmoralesAuthor Commented:
sorry, I did not realize you had posted.
If this works, I will definitely upgrade the points for you.
0
 
vmoralesAuthor Commented:
You've got it. Thanks.

To be fair; how much is this worth to you.
0
 
Éric MoreauSenior .Net ConsultantCommented:
>To be fair; how much is this worth to you.
I consider it to be moderate.
0
 
vmoralesAuthor Commented:
Adjusted points to 150
0
 
vmoralesAuthor Commented:
Thanks again.
0
All Courses

From novice to tech pro — start learning today.