当我点击 button
时,我想在 showRichMessageBox
中显示一个特定的单元格值,但是如果单击行的任意位置,此事件会显示单元格值。...!!
我怎样才能解决上述问题?
I have some logvalues which are big but it s already loaded in the cell so,
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);
}