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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

É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
Éric MoreauSenior .Net ConsultantCommented:
Don't you want to make a calendar control appear when you click a grid cell?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
Éric MoreauSenior .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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.