Robert Steely wrote:
From reading the language reference listbox entry, this doesn't appear
currently possible.
I need to add a popup menu temporarily to a listbox cell to ensure the user
populates the cell with a valid string value. Once the user selects an item
from the popup menu, I would remove the popup and place the corresponding
string in the cell as non-editable.
Right. Just set the cell type to TypeNormal, i.e., don't make it an
editable cell. When the user clicks on it, you get a CellClick event.
Then you should show a popup menu. I have a little listbox extension
method I frequently use for this:
Function PopUpCellChoices(extends lb As Listbox, row As Integer, column
As Integer, choices() As String) As Boolean
// Pop up the menu of choices for this cell. If the user picks one,
// store it in that cell and return True. Otherwise, return False.
Dim menu As New MenuItem
for each choice As String in choices
if choice = "-" then
menu.Append New MenuItem( MenuItem.TextSeparator )
else
Dim item As New MenuItem( choice )
menu.Append item
if choice = lb.Cell( row, column ) then item.Checked = true
end if
next
Dim choice As MenuItem = menu.PopUp
if choice is nil then return False
lb.Cell( row, column ) = choice.Text
return True
End Function
So, in your CellClick event, you just call me.PopUpCellChoices, passing
in the row, column, and list of values to choose frome, and it'll return
which one was chosen. You can then stuff this into the cell and do
whatever else you need to do.
In addition, you should probably draw some sort of indicator in the
listbox that lets the user know they can pop up a menu here. I do that
with this other listbox extension:
Sub DrawPopupIcon(extends lb As Listbox, g As Graphics)
static pic As Picture
if pic is nil then
pic = NewPicture( cell_popup_icon.width, cell_popup_icon.height, 32 )
Dim pg As Graphics = pic.graphics
pg.ForeColor = &c000000
pg.FillRect 0, 0, pic.width, pic.height
pg = pic.Mask.Graphics
pg.DrawPicture cell_popup_icon, 0, 0
end if
g.DrawPicture pic, g.width - 10, (g.height - pic.height)\2
End Sub
....but it requires a monochrome picture in your project called
cell_popup_icon. The shenanigans above with "pic" are just to take the
popup icon image (which has no transparency) and make it have a
transparent background. You could skip all that these days if you use a
transparent PNG, or set use two images in your project and set one as
the mask of the other.
HTH,
- Joe
--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|