0
我有,當我點擊其中一個窗體上的DataGridView,給了我正確的行/列索引點擊:上驗證[第三 如何得到正確的datagridview的有效行/列索引的MdiParent在C#
點擊列,第一行,給出了上述]。 但是,當這種形式是從MDI父叫,點擊thesame列三,排一(驗證)給出了這樣的:
下面是形式背後代碼:
var result = new DAO().RetrieveAllProjects().Select(r => new { r.Name }).ToList();
dataGridView1.DataSource = result;
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.HeaderText = "";
btn.Text = "View/Edit";
btn.Name = "edit";
btn.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btn2 = new DataGridViewButtonColumn();
btn2.HeaderText = "";
btn2.Text = "Verify";
btn2.Name = "verify";
btn2.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(btn);
dataGridView1.Columns.Add(btn2);
dataGridView1.Columns[0].Width = 290;
dataGridView1.AutoSize = true;
dataGridView1.CellClick += dataGridView1_CellClick;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(string.Format("ColumnIndex:{0}, RowIndex: {1}", e.ColumnIndex, e.RowIndex));
}
而且它的從MDI父稱這種方式:
projectsListForm pLF = new projectsListForm();
pLF.MdiParent = this;
pLF.Show();
我怎樣才能確保正確的行/列在MDI父強調
是有一些原因,你必須設置父形式一個'MdiParent',因爲這似乎是子表單中列索引的問題。爲什麼索引是不正確的,我不知道。 – JohnG