0

読み取り専用のデータグリッド ビューを持つフォームがあります。ユーザーがカーソルを上下に移動すると、強調表示された行に関連するグラフを表示したいと思います。DataGridView1_SelectionChangedイベント を使用しようとしまし たが、実行されません。

dataGridView1_CellContentClick_1トリックを行いますが、ユーザーがクリックする必要がありますが、これは避けたいと思います。

public partial class conf_results : Form
{
    private DataSet ds = new DataSet();
    private DataTable dt = new DataTable();
    private NpgsqlDataAdapter da = new NpgsqlDataAdapter();
    private NpgsqlCommandBuilder sBuilder = new NpgsqlCommandBuilder();
    public conf_results()
    {
        InitializeComponent();
        try
        {
            // PostgeSQL-style connection string
            // Making connection with Npgsql provider
            NpgsqlConnection conn;
            conn = new NpgsqlConnection(Properties.Settings.Default.connString);
            conn.Open();
            string sql = "SELECT m.orig_code,m.sejtvonal,round_dbl(m.parm_b,2),round_dbl(m.parm_c,2),round_dbl(m.variance,2),round_dbl(100 /(2^(m.ic50 - 1)),2),m.toxic,m.meres_id, " +
                "d.sejtvonal,round_dbl(d.parm_b,2),round_dbl(d.parm_c,2),round_dbl(d.variance,2),round_dbl(100 /(2^(d.ic50 - 1)),2),d.toxic,d.meres_id " +
                "from vegyulet_curve m, vegyulet_curve d where m.assay_id=d.assay_id and m.orig_code=d.orig_code "+
                "and m.sejtvonal='Mes-Sa' and d.sejtvonal='Dx5'";
            da = new NpgsqlDataAdapter(sql, conn);
            sBuilder = new NpgsqlCommandBuilder(da);
            DataSet ds = new DataSet();
            // filling DataSet with result from NpgsqlDataAdapter
            //da.Fill(ds);
            da.Fill(ds, "vegyulet_curve");
            // since it C# DataSet can handle multiple tables, we will select first
            dt = ds.Tables["vegyulet_curve"];
            // connect grid to DataTable
            dataGridView1.DataSource = ds.Tables["vegyulet_curve"];

             conn.Close();
                        }
        catch (Exception msg)
        {
            // something went wrong, and you wanna know why
            MessageBox.Show(msg.ToString());
            throw;
        }
    }

    private void DataGridView1_SelectionChanged(object sender, EventArgs e)
    {
        int i = dataGridView1.SelectedRows[0].Index;;    
        //  I am rewriting the code to use the chart on the form, 
        //  I was debugging, but I could ot get the control
    }

    private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex > -1)
        {
            //detailForm f = new detailForm(dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(),
            //dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString(),
            //dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
            //this.AddOwnedForm(f);
            //f.ShowDialog();                
            grafikon f = new grafikon(Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString()),
                dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(),
                Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString()),
                Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString()),
                Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString()));
            this.AddOwnedForm(f);
            f.ShowDialog();
        }

    }
4

1 に答える 1