> 一応試したコードを載せておきます。
>
>
コード: 全て選択
dim hList as HWND
>
> Function ListView_GetNextItem(ByVal hWnd As HWND,ByVal iStart As Long,ByVal flags As DWord) As Long
> Return SendMessage(hWnd,LVM_GETNEXTITEM,iStart As WPARAM,flags As LPARAM) As Long
> End Function
>
> hList=GetDlgItem(hMainWnd,ListView1) 'Createイベント内
>
> Sub MainWnd_ListView1_DblClick(ByRef nmListView As NMLISTVIEW)
> dim buf1[MaxPath_LV] as Byte
> dim buf2[MaxPath_LV] as Byte
> dim buf[255] as Byte
>
> ' 選択されている項目の位置を持つ
> Dim nSelect As Long
>
> ' 項目が選択されていない場合、-1が返ります
> nSelect=ListView_GetNextItem(GetDlgItem(hMainWnd,ListView1),-1,LVNI_ALL Or LVNI_SELECTED)
>
> if nSelect<>-1 then
> ListView_GetItemText(hList,0,0,buf1,MaxPath_LV)
> ListView_GetItemText(hList,0,1,buf2,MaxPath_LV)
> Elseif nSelect=-1 then
> ListView_GetItemText(hList,lvItem.iItem,0,buf1,MaxPath_LV)
> ListView_GetItemText(hList,lvItem.iItem,1,buf2,MaxPath_LV)
> End If
>
> wsprintf(buf,"%s%s",buf2,buf1)
> MessageBox(hMainWnd,buf,0,MB_OK)
> End Sub
項目が選択されているなら 0 の項目を取得、項目が選択されていないなら選択されている項目を取得になってます...。
If文が逆なんではないかと思います。
※lvItem.iItem に値が格納されていないのでインデックスは必ず 0 になります
項目が選択されていない場合、メッセージボックスで注意するだけにしました。勝手に。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
dim hList as HWND
Function ListView_GetNextItem(ByVal hWnd As HWND,ByVal iStart As Long,ByVal flags As DWord) As Long
Return SendMessage(hWnd,LVM_GETNEXTITEM,iStart As WPARAM,flags As LPARAM) As Long
End Function
hList=GetDlgItem(hMainWnd,ListView1) 'Createイベント内
Sub MainWnd_ListView1_DblClick(ByRef nmListView As NMLISTVIEW)
dim buf1[MaxPath_LV] as Byte
dim buf2[MaxPath_LV] as Byte
dim buf[255] as Byte
' 選択されている項目の位置を持つ
dim nSelect As Long
' 項目が選択されていない場合、-1が返ります
nSelect=ListView_GetNextItem(hList,-1,LVNI_ALL Or LVNI_SELECTED)
if nSelect<>-1 then ' 項目が選択されているなら
ListView_GetItemText(hList,nSelect,0,buf1,MaxPath_LV)
ListView_GetItemText(hList,nSelect,1,buf2,MaxPath_LV)
wsprintf(buf,"%s%s",buf2,buf1)
MessageBox(hMainWnd,buf,0,MB_OK)
else ' 項目が選択されていないなら
MessageBox(hMainWnd,"選択範囲が無効です。",0,MB_OK)
end if ' if nSelect<>-1 then
End Sub
単純に選択されている項目のデータを取得したいなら選択されている項目のインデックスをListView_GetItemText関数の第二引数に指定します。
LVITEM構造体の iItem メンバを指定したい場合、iItem にインデックスを格納してからでないといけません。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
dim hList as HWND
Function ListView_GetNextItem(ByVal hWnd As HWND,ByVal iStart As Long,ByVal flags As DWord) As Long
Return SendMessage(hWnd,LVM_GETNEXTITEM,iStart As WPARAM,flags As LPARAM) As Long
End Function
hList=GetDlgItem(hMainWnd,ListView1) 'Createイベント内
Sub MainWnd_ListView1_DblClick(ByRef nmListView As NMLISTVIEW)
dim buf1[MaxPath_LV] as Byte
dim buf2[MaxPath_LV] as Byte
dim buf[255] as Byte
' 項目が選択されていない場合、-1が返ります
lvItem.iItem=ListView_GetNextItem(hList,-1,LVNI_ALL Or LVNI_SELECTED)
if lvItem.iItem<>-1 then ' 項目が選択されているなら
ListView_GetItemText(hList,lvItem.iItem,0,buf1,MaxPath_LV)
ListView_GetItemText(hList,lvItem.iItem,1,buf2,MaxPath_LV)
wsprintf(buf,"%s%s",buf2,buf1)
MessageBox(hMainWnd,buf,0,MB_OK)
else ' 項目が選択されていないなら
MessageBox(hMainWnd,"選択範囲が無効です。",0,MB_OK)
end if ' if nSelect<>-1 then
End Sub
戻り値の意味や扱い方、指定すべきデータなど覚えるのに苦労しますよねぇ...。