0

i build application who take all the files in my ListView (pcap files )and start to play all the packets. what i want is that the currently file that play will mark and after this file finish the next file after will be marked and the focus will be all the time on the selected file (i dont want to manually acroll to see the file) what i have now is that the first file marked and after it finish my application markes also the second and after the third together.

tis is my start button:

private void btnStart_Click(object sender, EventArgs e)
{
    string filePath = string.Empty;
    ThreadPool.QueueUserWorkItem(delegate
    {
        for (int i = 0; i < lvFiles.Items.Count; i++)
        {
            this.Invoke((MethodInvoker)delegate
            {                        
                lvFiles.EnsureVisible(i);
                lvFiles.Items[i].Selected = true;
                filePath = lvFiles.Items[i].Tag.ToString();
            });

            PcapFile pcapFile = new PcapFile();
            pcapFile.sendQueue(filePath, adapter);
        }
    });
}

lvFiles is my ListView, PcapFile is my class and pcapFile.sendQueue is the method who start the play.

4

1 回答 1

1

您应该为此调用Select()列表视图。也不要忘记在选择下一个项目之前取消选择当前项目。

    for (int i = 0; i < lvFiles.Items.Count; i++)
    {
        this.Invoke((MethodInvoker)delegate
        {                        
            lvFiles.EnsureVisible(i);
            lvFiles.Items[i].Selected = true;
            lvFiles.Select();
            filePath = lvFiles.Items[i].Tag.ToString();
        });

        PcapFile pcapFile = new PcapFile();
        pcapFile.sendQueue(filePath, adapter);
        lvFiles.Items[i].Selected = false;
    }
于 2013-01-02T21:06:50.450 回答