Hi, guys,
How can I get the value of the selected row in a ListBox? The ListBox is dynamic and created based on the other user actions?
Any help is highly appreciated.
Thank you,
Val
Hi, guys,
How can I get the value of the selected row in a ListBox? The ListBox is dynamic and created based on the other user actions?
Any help is highly appreciated.
Thank you,
Val
Loop through the rows until you find the selected one with Selected = True
http://documentation.xojo.com/index.php/ListBox.Selected
Then use the Cell method http://documentation.xojo.com/index.php/ListBox.Cell
make 2 Properties
myrow As Integer
mycolumn As Integer
ListBox.CellClick:
myrow = row
mycolumn = column
ListBox.Change:
if me.ListCount > 0 then
if me.Selected(myrow) = true Then
MsgBox me.Cell(myrow, mycolumn)
end if
end if
Hi, Axel,
Thank you for your help. This works.
I wonder if the ListBox.CellClick code could be some way placed into the ListBox.Change so that the navigation could be done with the arrow keys on the keyboard and any use of mouse and clicking is avoided.
Thank you very much,
Val
You want to highlight the Cell using the arrow keys?
celltext is a property (the Text of the selected Cell)
celltext As String
ListBox.KeyDown
select case asc(key)
case 31
if me.Selected(me.ListIndex) = false then
me.Selected(0) = true
me.ListIndex = me.ListIndex - 1
myrow = me.ListIndex
mycolumn = 0
me.Invalidate
celltext = me.Cell(myrow, mycolumn)
end if
if myrow = me.LastIndex then return False
myrow = myrow + 1
celltext = me.Cell(myrow, mycolumn)
case 30
if me.Selected(me.ListIndex) = false then
me.Selected(0) = true
myrow = 0
mycolumn = 0
me.Invalidate
celltext = me.Cell(myrow, mycolumn)
end if
if myrow = 0 then return False
myrow = myrow - 1
celltext = me.Cell(myrow, mycolumn)
case 28
if mycolumn = 0 then
return False
else
mycolumn = mycolumn - 1
me.Invalidate
celltext = me.Cell(myrow, mycolumn)
Return True
end if
case 29
if mycolumn = me.ColumnCount-1 then
return False
else
mycolumn = mycolumn + 1
me.Invalidate
celltext = me.Cell(myrow, mycolumn)
Return True
end if
end select
Axel, thank you very much. All works like a charm.
Val
Valeriy:
I made a copy of the currently selected row in a “Status” TextField (read only, located at the window bottom). As times goes by, I am realy happy by this addition, I use it very often.
Thanks Axel! This solved a big hassle I was having.