Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

LV_GetSelectedText()


  • Please log in to reply
1 reply to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
WARNING: This is old thread. It is continued here.

Returns text from selected rows in ListView (in a user friendly way IMO.)
Compatible with both AHK_L and AHK basic.

Function
LV_GetSelectedText(FromColumns="", ColumnsDelimiter="`t", RowsDelimiter= "`n") { ; by Learning one
if FromColumns = ; than get text from all columns
{
Loop, % LV_GetCount("Column") ; total number of columns in LV
FromColumns .= A_Index "|"
}
if (SubStr(FromColumns,0) = "|")
StringTrimRight, FromColumns, FromColumns, 1
Loop
{
RowNumber := LV_GetNext(RowNumber)
if !RowNumber
break
Loop, parse, FromColumns, |
{
LV_GetText(FieldText, RowNumber, A_LoopField)
Selected .= FieldText ColumnsDelimiter
}
if (SubStr(Selected,0) = ColumnsDelimiter)
StringTrimRight, Selected, Selected, 1
Selected .= RowsDelimiter
}
if (SubStr(Selected,0) = RowsDelimiter)
StringTrimRight, Selected, Selected, 1
return Selected
}
Example
Gui 1: Add, ListView, x5 y5 w250 h300, First name|Last name|Occupation
LV_Add("","Jim","Tucker","Driver")
LV_Add("","Jill","Lochte","Artist")
LV_Add("","Jessica","Hickman","Student")
LV_Add("","Mary","Jones","Teacher")
LV_Add("","Tony","Jackman","Surfer")
Gui 1: Show, w260 h310
return

F1::MsgBox % LV_GetSelectedText() ; get text from selected rows
F2::MsgBox % LV_GetSelectedText("1|3") ; get text from selected rows, but only from 1. and 3. column
F3::MsgBox % LV_GetSelectedText("1|3","|","#") ; same as above but use custom delimiters in returning string


Lucid_Method
  • Members
  • 147 posts
  • Last active: Dec 06 2014 08:39 AM
  • Joined: 19 Apr 2010
Useful function thanks :)
Posted Image
Macro Everything
Lucid_Method Index