0

以下に、listView で選択した行からインデックスを取得するコードをいくつか示します。ただし、これはユーザーが最初の列をクリックした場合にのみ機能します。しかし、4 つの列がある場合、ユーザーが listView の行の任意の場所をクリックできるようにするにはどうすればよいでしょうか?

private void lvRegAnimals_SelectedIndexChanged(object sender, EventArgs e)
{
    int index = lvRegAnimals.FocusedItem.Index;
    // Code here to pass the index to method....
}
4

2 に答える 2

2

ListView.FullRowSelectを trueに設定する必要があります。

于 2012-07-06T07:09:46.453 に答える
0

プロパティを使用ListView.SelectedItemsして、ここで作業を行うことができます。このようなもの

private void ListView1_SelectedIndexChanged_UsingItems(
        object sender, System.EventArgs e)
    {

        ListView.SelectedListViewItemCollection breakfast = 
            this.ListView1.SelectedItems;

        double price = 0.0;
        foreach ( ListViewItem item in breakfast )
        {
            price += Double.Parse(item.SubItems[1].Text);
        }

        // Output the price to TextBox1.
        TextBox1.Text = price.ToString();
    }

詳細はこちら

于 2012-07-06T07:09:09.273 に答える