Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid dblClick Problem

Status
Not open for further replies.

Amador

Programmer
Apr 6, 2002
5
0
0
CA
I am using Datagrid and ADO 6.0, to maintain a database table (change, delete and add data) , some of the fields are dates, in those fields(cells) I am using dblclick in order to get the date from the calendar control, this part works well.
My problem is: after get the date, the cell can not be changed using the keyboard, if I type something in the cell it gets empty and doesn’t accept data or ESC. The only way to fix it (exit the cell or hit a command button) is clicking twice in the same cell or in another cell or in a command button.

What to do to avoid this situation ?

Thanks for your help.

Amador.

 
Is your AllowUpdate property set to true for the DBGRID?
 
Set the focus back to the grid, and possibly set the Col/Row property to the one in question again.

frmCalendar.Show vbModal
DataGrid1.Columns(2).Text = frmCalendar.Selection
DataGrid1.SetFocus
DataGrid1.Col = 2
DataGrid1.Row = 10
 
Thank you for the answer,

Yes, the AllowUpdate property is set to true

I did the CCLINT recommendation, but still the same problem
 
I am not sure wether you are using a datagrid (part of MSchart control) or a dbgrid. Can you list the controls you are using and list a sample of the code in question?
 
When I use a grid, I add a textbox for editing. Set the textbox to invisible. When the grid is clicked, or double clicked, I move the textbox to the cell location setting the size of the textbox to the size of the cell and then making it visible. You can then save the contents of the textbox to the cell upon some other action such as lostfocus etc. It works great. You can use listboxes or combos in the same manner. There are many examples of this out there in web-land.

 
Thanks to all of you, , I contacted Microsoft and it is a bug "Cannot edit cells in DataGrid after closing a modal dialog", a similar problem is addressed in
This is the code to solve the problem.

Option Explicit

Private Declare Sub mouse_event Lib "user32" ( _
ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Private Const MOUSEEVENTF_LEFTUP = &H4

Private Sub DataGrid1_DblClick()
With DataGrid1
frmCalendar.Show vbModal
.Text = CStr(gDate)

End With

mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

End Sub
 
Why bother using a double click?

For the column which is open a modal form set the Button property to True:

DataGrid1.Columns("SomeDateField").Button = True

Then open the Modal form from the DataGrid's ButtonClick event.

 
Thank You CCLINT,

Excellent alternative, I will use this way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top