如何从其他用户控件访问listView?

时间:2019-04-17 15:43:03

标签: c# windows

我想从其他控件访问listView来从结构中输入数据,但我不知道该怎么做。`SavethescoreScoreDialog = new Savethescore();         HallofGlory HofG =新的HallofGlory();

    private void saveTheScoreToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ScoreDialog.ShowDialog();

        if (ScoreDialog.DialogResult == DialogResult.OK)
        {
            string sLevel = "Level 1";

            if (bLevel1)
                sLevel = "Level 1";
            if (bLevel2)
                sLevel = "Level 2";
            SStat Player = new SStat(ScoreDialog.textBox1.Text, sLevel, m_iHits, m_iShots, m_iSpeed, m_iSpeed, CountPercents(m_iHits, m_iShots));


            ListViewItem NewPlayer = new ListViewItem(Player.m_sName);
            NewPlayer.SubItems.Add(Player.m_sLevel);
            NewPlayer.SubItems.Add(Player.m_iHits.ToString());
            NewPlayer.SubItems.Add(Player.m_iShots.ToString());
            NewPlayer.SubItems.Add(Player.m_iSpeed.ToString());
            NewPlayer.SubItems.Add(Player.m_dPercentage.ToString() + "%");
            HofG.listView1.Items.Add(NewPlayer);
        }
    }`

1 个答案:

答案 0 :(得分:0)

这段视频帮助了我。 https://youtu.be/mECkft9LG4k 我现在可以按照此处介绍的所有步骤来使用我的工具。