ShowRichMessageBox
当我单击时,我想在一行中显示一个特定的单元格值,button
但是如果单击该行上的任意位置,此事件将显示单元格值....!
这里有什么问题.....我该如何解决上述问题???
我有一些很大的对数值,但它已经加载到单元格中,所以,
Is it possible to expand the row when i select a particular row in the datagridview???
public LogView()
{
InitializeComponent();
this.dataGridView2.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView2_buttonCol);
bindingList = new SortedBindingList<ILogItemView>();
dataGridView2.DataSource = bindingList;
this.dataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.dataGridView2.MultiSelect = false;
var buttonCol = new DataGridViewButtonColumn(); // The button to display a particular cell value when clicks//
buttonCol.Name = "ButtonColumnName";
buttonCol.HeaderText = "Show";
buttonCol.Text = "View";
buttonCol.UseColumnTextForButtonValue = true;
dataGridView2.Columns.Add(buttonCol);
}
private void dataGridView2_buttonCol(object sender, DataGridViewCellEventArgs e)
{
string name = Convert.ToString(dataGridView2.SelectedRows[0].Cells[2].Value);
ShowRichMessageBox("Code", name);
}
编辑:
if (e.ColumnIndex != 0) // Change to the index of your button column
{
return;
}
if (e.RowIndex > -1)
{
string name = Convert.ToString(dataGridView2.Rows[e.RowIndex].Cells[2].Value);
ShowRichMessageBox("Code", name);
}