0

クラスとコードIDのメソッドを介してコードを列にロードするグリッドビューがあります:

            Queue objQueue = new Queue();
            dataGridView1.DataSource = objQueue.GetAllQueue();
            DataGridViewButtonColumn btnFile = new DataGridViewButtonColumn();
            btnFile.UseColumnTextForButtonValue = true;
            btnFile.Name = "btnViewFile";
            btnFile.Text = "View";
            btnFile.HeaderText = "View Image";
            dataGridView1.Columns.Add(btnFile);

問題なくデータグリッドビューにボタンをロードできますが、このボタンをバインドして、新しいデザインのフォームまたはWindowsの画像とファックスビューアを介して画像リンクを開くにはどうすればよいですか。

4

3 に答える 3

0

イベントハンドラーをDataGridビューに次のようにアタッチできます。

dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);

そしてそれを次のように扱います

void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0) //Or your Button Index location
            {
                MessageBox.Show("Here");
            }
        }

次に、新しいフォームを作成して表示したり、必要に応じて画像リンクを開いたりできます。

于 2012-09-27T11:00:35.060 に答える
0

これはうまくいくはずです

btnFile.Click += btnFile_Click;

ここで btnFile_Click ファイルを定義して、Response で画像をストリーミングします

于 2012-09-27T10:31:41.330 に答える
0

解決 :

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex ==1) //Assuming the button column as second column, if not can change the index
            {
                //check if anything needs to be validated here
                Form1 f = new Form1();
                f.navId = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                f.Show();

            }
        }

上記のコードでは、次のステートメントを使用して ID の値を割り当てます。 f.navId = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

これを機能させるには、ターゲット フォームでパブリック変数を宣言するだけです (この例では navId)。

于 2012-09-27T10:46:04.910 に答える