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

Bringing a control to the front with code

Status
Not open for further replies.

freewilly

Programmer
Feb 19, 2001
43
0
0
AU
Hi team

How do I force a control to be on top of other controls with code?

Thanks

FW
 
In Design View, focus the control, then execute:
RunCommand acCmdBringToFront

If you're talking about doing this in Form View, you can't. Controls, such as text boxes, which allow user interaction will automatically come to the top when they receive the focus. Controls that have no user interaction can't receive the focus, so they fall underneath.

If this is your problem, maybe I can suggest a design modification that will accomplish a similar effect. Tell me why you want to bring the control to the front.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thanks Rick.

I have a list view and I want the user to be able to modify the values. I have done this in VB with the following code

txtEdit.SetFocus
txtEdit.Width = lvwInventoryAllocation.ColumnHeaders(htiHitTestInfo.lSubItem + 1).Width - 50
txtEdit.Left = lvwInventoryAllocation.ColumnHeaders(htiHitTestInfo.lSubItem + 1).Left + lvwInventoryAllocation.Left + 500
txtEdit.Height = lvwInventoryAllocation.ListItems(htiHitTestInfo.lItem + 1).Height
txtEdit.Top = lvwInventoryAllocation.ListItems(htiHitTestInfo.lItem + 1).Top + lvwInventoryAllocation.Top + 60
txtEdit.Text = lvwInventoryAllocation.ListItems(htiHitTestInfo.lItem + 1).SubItems(htiHitTestInfo.lSubItem)
txtEdit.SelLength = Len(txtEdit)
txtEdit.SelStart = 0
txtEdit.Tag = lvwInventoryAllocation.ListItems(htiHitTestInfo.lItem + 1).SubItems(2)
txtEdit.Visible = True

The mousedown event sets the htiHitTestInfo so that I know which list item i'm clicking on.

This works nicely in VB but in Access txtEdit remains beneath the ListView.

RunCommand acCmdBringToFront does not seem to ba available at run time.

Any ideas are appreciated.

The runcom

FW
 
I guess the text box not coming to the top must have something to do with ListView being an ActiveX control.

The Access built-in controls aren't the standard Windows controls. They're "lightweight" versions instead, and they have their own properties and methods. That's why they don't always behave exactly like the Windows controls VB uses.

One thing you might consider trying is the Microsoft Forms 2.0 Text Box control. I imagine it's closer to the Windows standard Text Box, though I'm not sure.

Another idea is to switch to using a TreeView control, with the lines and icons hidden and all nodes at the root level. TreeView allows in-place editing, so you wouldn't need the text box (if I understand what you're doing) and wouldn't have to do the hit test yourself.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Uh...what worked, exactly? For other members who might have the same problem.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Rick's right - you don't seem to be able to move it in front in the code, but TreeView is a much slicker looking control anyway so I use them whenever I can get away with it!

Just for future reference:
I've used the same sort of technique as you in VB6 to implement a drop-down combo in front of a DataGrid control and discovered the .ZOrder property which allows you to position several overlapping controls in front, behind or anywhere in between in the same way as you would with windows on your desktop.
Also, using With would have made the code a bit easier on the eye
Code:
Dim ColNumber as Integer
ColNumber = htiHitTestInfo.lSubItem + 1
txtEdit.SetFocus
With lvwInventoryAllocation.ColumnHeaders(ColNumber)
  txtEdit.Width = .Width - 50
  txtEdit.Left = .Left+lvwInventoryAllocation.Left+500
  txtEdit.Height = .Height
  txtEdit.Top = .Top+lvwInventoryAllocation.Top+60
  txtEdit.Text = .SubItems(htiHitTestInfo.lSubItem)
  txtEdit.SelLength = Len(txtEdit)
  txtEdit.SelStart = 0
  txtEdit.Tag = .SubItems(2)
  txtEdit.Visible = True
End With
Just a thought
[noevil]


PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top