4

DGV にリンクされたコンテキスト メニュー ストリップがあります。DGV 内のセルをクリックすると、コンテキスト メニュー ストリップが開きます。「plotStripMenuItem」をクリックすると、基本的にテキスト ファイルからデータを読み取り、グラフをプロットして統計を計算するフォーム (formPlot) を開くことができます。 (formPlot が閉じられると) DGV の前にクリックされた行に戻ります。

これを行うには、「int clickedRow」を使用して、formPlot を開く前にクリックされた行番号を保存し、formPlot を閉じた後にそれを使用して DGV を更新します。

    private void plotToolStripMenuItem_Click(object sender, EventArgs e)
    {
        //get the row number which was clicked 
        string strClickedRow = DGVLeft.CurrentCellAddress.Y.ToString();
        int clickedRow = Convert.ToInt16(strClickedRow);

        FormPlot formPlot = new FormPlot(strLot, pathLD);
        formPlot.ShowDialog();

        DGVLeft.Rows[clickedRow].Cells[0].Value = formPlot.columnA;
        DGVLeft.Rows[clickedRow].Cells[1].Value = formPlot.ColumnB;
        DGVLeft.Rows[clickedRow].Cells[2].Value = formPlot.columnC;
        DGVLeft.Rows[clickedRow].Cells[3].Value = formPlot.columnD;
    }

ほとんどの場合、これは期待どおりに機能します。しかし、formPlot を開く前にクリックした DGV セルが時々更新されないことに気付きました。代わりに、行番号 0 を更新しました。

たとえば、行 7 をクリックしましたが、formPlot から戻ると、DGV 行 0 の値が更新されました。DGV 行番号 7 の値ではありません。

私には、行7をクリックして変数に保存したため、行0が更新される方法があります。

私はここで何かを逃していますか?

4

1 に答える 1

1

これで問題が解決する場合と解決しない場合がありますが、なぜ行番号を文字列に変換して元に戻すのですか?

    //get the row number which was clicked 
    string strClickedRow = DGVLeft.CurrentCellAddress.Y.ToString();
    int clickedRow = Convert.ToInt16(strClickedRow);

ただあるべき

    //get the row number which was clicked 
    int clickedRow = DGVLeft.CurrentCellAddress.Y;
于 2012-11-13T05:12:55.573 に答える