Adding EMAIL button to each row of ListView Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asghar5676
Posts: 18
Joined: 22 Aug 2017, 01:24

Adding EMAIL button to each row of ListView

Post by asghar5676 » 25 Aug 2017, 06:03

Hi all,

I am a beginner and I am now trying to add an EMAIL button to each row of my ListView and I have no idea how to achieve that.
The intent is by clicking on email button, an email to be sent for to that particular user

Image

Code: Select all

#SingleInstance force
SetWorkingDir %A_ScriptDir% 

Data_Source:= "textInput.txt"
LV_Table(Data_Source,"`t",1,Title:="Enquery result")

Return




LV_Table(Data_Source, delimiter="`t",UseHeader=1,Title=""){
if FileExist(Data_Source) ;if file exists use it as source
FileRead, Data_Source, %Data_Source% ;read in and store as variable
data_obj := StrSplit(Data_Source,"`n","`r") ;parse earch row and store in object
rowHeader:=StrReplace(data_obj.RemoveAt(1),Delimiter,"|",Numb_Columns) ; Remove header from Object and convert to pipe delimited
if (useHeader=0){
	loop, % Numb_Columns+1
		RH.="Col_" A_Index "|"
	rowHeader:=RH
}
dCols:= (Numb_Columns<10) ? 400: ((Numb_Columns<80) ? 650 : 1100) ;if cols <10 use 400; if cols <80 use 650 ; else use 1100
dRows:= (data_obj.MaxIndex() >27) ? 26 : data_obj.MaxIndex() ;if rows >27 use 26 else use # of rows
Gui, Table_View: New,,%Title% ;create new gui window and set title
Gui, Font, s12, Century Gothic
Gui, Add, ListView, r%dRows% w%dCols% report grid, % rowHeader ;set headers
For Each, Row In data_obj ;add the data lines to the ListView
   LV_Add("", StrSplit(Row, Delimiter)*) ;LV_Add is a variadic function
LV_ModifyCol(1, "Auto") , LV_ModifyCol(2, 100), LV_ModifyCol(2, "SortDesc"), LV_ModifyCol(2, "center")
Gui, Table_View:Show
}
The "textInput.txt" file is tab delimited file and the content of it is like below:
Spoiler
Can some one help me doing that?
(columns 1 currently contains some dummy usernames for the sake of example. In real life, there is no duplicate value)

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Adding EMAIL button to each row of ListView  Topic is solved

Post by Nightwolf85 » 25 Aug 2017, 08:20

I'm not sure how to add a button to each row, but I have in the past created a menu that showed on right click. You can then get the info from the right clicked row and use that to send an email.

Here is a small example script of how this would look:

Code: Select all

Menu, ListRCMenu, Add, Send Email, sendEmail ; Create the Menu to show when list view is right clicked

GUI, Main:New,, Example
GUI, Add, ListView, r5 w200 Grid, Column1|Column2
Loop 10
	LV_Add("","Email_" A_Index, "Time_" A_Index)
GUI, Show
Return

MainGUIClose:
ExitApp

MainGuiContextMenu: ; This is automatically called when the GUI is rightclicked (or when the apps key is pressed I think)
	IF (A_EventInfo) { ; This will be the row number selected when right-clicked, if right clicking outside the list view will be 0 (False)
		rightClickedRow := A_EventInfo ; Save the selected row for use in getting email.
		Menu, ListRCMenu, Show ; Show the Rightclick menu
	}
Return

sendEmail: ; Called when the menu item is selected
	GUI, Main:+OwnDialogs
	GUI, Main:Default
	LV_GetText(useEmail, rightClickedRow, 1) ; Get the text from column 1 of the list view
	MsgBox, Email Address selected is %useEmail%
Return
Edit: Added comments in code to help show what it happening, and changed to a slightly more efficient version.

Edit2: You could also make an email get sent on a row double click using the glabel of the ListView, just thought of that as an alternative.

garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Adding EMAIL button to each row of ListView

Post by garry » 25 Aug 2017, 13:49

another idea , click on ICO to start email or program

Code: Select all

;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=36285 ---
;- show email-icon if column3 with  @ exists
;- put  email-icon in folder %a_scriptdir%\ICO
;- when click on icon starts program or email

R3I=%a_scriptdir%\ICO                ;- folder for icons / put icons here for test > printer.ico and text.ico or thunderbird.ico if want send email
ifnotexist,%r3i%
  filecreatedir,%r3i%
XXA:=R3I . "\printer.ico"            ;- example = printer.ico
XXB:=R3I . "\text.ico"               ;-              text.ico
XXC:=R3I . "\thunderbird.ico"        ;- email
Gui,2:default
GUI,2:Font,cBlack,Fixedsys

e4x=
(Ltrim Join`r`n
VOLUME;;%A_WinDir%\system32\sndvol32.exe
CHARMAP;;%A_WinDir%\system32\charmap.exe
Notepad;;%A_WinDir%\system32\notepad.exe
user1;05:26;garry@aol.pl
user2;03:11;harry@aol.pt
)

Gui,2:Add, ListView, backgroundGray grid x10 y30  h800 w600 +hscroll altsubmit vMLV1A gMLV1B      , Name|Hours-Used|Email
gosub,lb
gui,2:show, x100 y10 h870 w630,LV_ICON_TEST
return
2Guiclose:
exitapp
;-------------------------------------
lb:
Gui,2:Submit,nohide
Gui,2:ListView,mlv1a
t1:=250
t2:=330
t3:=0
   LV_ModifyCol(1,T1)
   LV_ModifyCol(2,T2)
   LV_ModifyCol(3,T3)
  ;ILStatus := IL_Create(1,1,0)                ;small
   ILStatus := IL_Create(1,1,1)                ;bigger
   LV_SetImageList(ILStatus, 1)
LV_Delete()
;GuiControl,2: -Redraw,MLV1a
loop,parse,e4x,`n,`r
  {
  x:=a_loopfield
  c1=
  c2=
  c3=
  IconNumber := IL_Add(ILSTATUS, "%pictxx05%" )      ;- clear with picture which not exist
  IconNumber := IL_Add(ILSTATUS,XXC)
  stringsplit,C,x,`;,
  SplitPath,C3, name, dir, ext, name_no_ext, drive
  IconNumber := IL_Add(ILSTATUS, C3 )
  EXEX2=txt,doc
  if EXT contains %EXEX2%
     IconNumber := IL_Add(ILSTATUS, XXB )            ;- text.ico for extension txt doc
  ;------- example add printer.ico -----------       <<<<<<<<  printer.ico if column-1 called 'Printers'
  if (c1="Printers")
      IconNumber := IL_Add(ILSTATUS, XXA )
  if c3 contains @
      IconNumber := IL_Add(ILSTATUS,XXC)
  ;-------------------------------------------
  LV_Add("icon" . IconNumber ,C1,C2,c3)
  }
;GuiControl,2: +Redraw,MLV1a
LV_ModifyCol(1,"right")     ;- move text to right
return
;-----------------------------------------------------------------
mlv1b:
Gui,2:submit,nohide
Gui,2:ListView, mlv1a
tx1:=50
If A_GuiEvent = Normal
   {
    MouseGetPos,x,y
       {
       if (x<tx1)
          {
          LV_GetText(C3,A_EventInfo,3)
          if c3 contains @
             {
             run, mailto:%c3%?subject=tonight&body=Test1`%0ATest2
             return
             }
          ifexist,%c3%
              run,%c3%
          }
       }
}
return
;============= end script =================================

asghar5676
Posts: 18
Joined: 22 Aug 2017, 01:24

Re: Adding EMAIL button to each row of ListView

Post by asghar5676 » 26 Aug 2017, 05:56

Thanks to you both Nightwolf85 & garry. That was very generous of you guys. Really appreciate your time.

Post Reply

Return to “Ask for Help (v1)”