アプリ版:「スタンプのみでお礼する」機能のリリースについて

C#でSendMessageを使用してListViewのアイテムを選択する方法で悩んでいます。

[StructLayout( LayoutKind.Sequential, CharSet = CharSet.Auto )]
public struct LVITEM {
public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int lParam;
public int iIndent;
// (_WIN32_WINNT >= 0x501)
public int iGroupId;
public uint cColumns;
public IntPtr puColumns;
}

・・・・
public void HogeHoge() {
LVITEM lvi = new LVITEM();
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
lvi.stateMask = 0x000F;
SendMessage( hLV, LVM_SETITEMSTATE, 0, ref lvi );


LVM_SETITEMSTATEでは選択できないのでしょうか?
OSはXPです。

A 回答 (1件)

 こんばんは。



 当方はwindows2000です。試して見ましたが、選択出来ました。
 もしかして、フラグの数字を誤っているのかもしれません。
 一応乗せて置きますので、参考程度に。

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct LVITEM
{
public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int lParam;
public int iIndent;
// (_WIN32_WINNT >= 0x501)
public int iGroupId;
public uint cColumns;
public IntPtr puColumns;
}

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static Int32 SendMessage(IntPtr hWnd, UInt32 uMsg, UInt32 wParam, ref LVITEM lParam);

public const int LVIF_TEXT = 0x0001;
public const int LVIF_IMAGE = 0x0002;
public const int LVIF_PARAM = 0x0004;
public const int LVIF_STATE = 0x0008;
//(_WIN32_IE >= 0x0300)
public const int LVIF_INDENT = 0x0010;
public const int LVIF_NORECOMPUTE = 0x0800;

public const int LVIS_FOCUSED = 0x0001;
public const int LVIS_SELECTED = 0x0002;
public const int LVIS_CUT = 0x0004;
public const int LVIS_DROPHILITED = 0x0008;
public const int LVIS_ACTIVATING = 0x0020;

public const int LVIS_OVERLAYMASK = 0x0F00;
public const int LVIS_STATEIMAGEMASK = 0xF000;

public const int LVM_FIRST = 0x1000;
public const int LVM_SETITEMSTATE = LVM_FIRST + 43;

public void HogeHoge()
{
IntPtr hLV = listView1.Handle;
LVITEM lvi = new LVITEM();
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
lvi.stateMask = 0x000F;
SendMessage(hLV, LVM_SETITEMSTATE, 0, ref lvi);
}

この回答への補足

エクスプローラのListViewのアイテムを選択したいのですが
LVM_SETITEMSTATEを送るとComctl32.dllでエラーが発生します

補足日時:2009/02/13 15:22
    • good
    • 0
この回答へのお礼

ご解答ありがとうございます

フラグ値は合ってます
いろいろ、やってみたのですがうまく行きません

エクスプローラのListViewのアイテムを選択したいのですが・・・
LVM_SETITEMSTATEでListViewのアイテムを選択するには?(2)としてソースコードを投稿いたします。

お礼日時:2009/02/12 19:24

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!