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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make popups in Datagrid 1

Status
Not open for further replies.

poltergeist

Programmer
Jul 16, 2003
173
CL
An example how to capture the mouseclick an make different popups in each column.

Option Explicit
Dim rwSel As Integer

Private Sub DGrid_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim clSel As Integer
Dim intCnt As Integer
Dim refWid As Integer
If Button = 2 Then
clSel = -1
X = X - 390
For intCnt = DGrid.LeftCol To DGrid.Columns().Count - 1
If X < refWid Then Exit For
clSel = intCnt
refWid = refWid + DGrid.Columns(intCnt).Width
Next intCnt
rwSel = Int((Y - 195) / DGrid.RowHeight)
If rwSel <= (DGrid.ApproxCount - 1) Then
Select Case clSel
Case -1 To 12
PopupMenu pop3
Case 13
PopupMenu pop2
End Select
End If
End If
End Sub


the value -1 is to give back the click on the selector
If thier is anyone with a other great idea please let me know.

Peter
 
Looks a little complicated - to be honest though I didn't try to digest at all the rest of what you are trying to accomplish...

Private Sub DataGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Select Case DataGrid1.ColContaining(X)
Case -1 To 12
PopupMenu pop3
Case 13
PopupMenu pop2
End Select
End If
End Sub
 
It's good idea but also i need the row

I'll give you the Star

Thanks Peter Guhl
 
>but also i need the row
+But your code isn't accurately returning the true row number.

First of all, this:

rwSel = Int((Y - 195) / DGrid.RowHeight)
Could be replaced with this:

rwSel = DataGrid1.RowContaining(Y)

It'll be a little easier.

Secondly, it will only report the Visible row number. Say your grid shows 10 rows at a time. If you scroll down two pages and click the first Visible row, you may expect it to report back row 20.
But it will report back row 0 instead, and the actual 30th record will be row 10.
If you have 1000 records, and the grid shows 10 records, and you scroll down to the 1000th record, that row number is 10.
So, the Row property returns the Visible row number between 0 and the last visible row. The Row method however, will move the current Row the number of rows indicated form the Top visible row.
(If I have 1000 records an the cursor is on the 500th record and I set .Row = 499, then guess what? You'll be then on record 1000. If I set .Row = 750 while on the 500th record, you'll get an error, even though there are 1000 records).

If you need to know the current record for some reason, or even the current &quot;record number&quot;, then use:

Dim rsClone As ADODB.Recordset
set rsClone = DataGridRS.Clone
rsClone.Bookmark = DataGrid1.RowBookmark(DataGrid1.Row)
?rsclone.AbsolutePosition

(Assumes that DataGridRS is the datasource that the grid is bound to - could also be an Adodc1.Recordset - and that DataGrid1.Row is >= 0)

 
Oops. Correction (for the MouseDown only)

rsClone.Bookmark = DataGrid1.RowBookmark(DataGrid1.RowContaining(Y))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top