如果是这样,我们如何分别处理每个的 cellcontentclick 事件?我正在动态添加列。这是我的代码:-
dataGridViewShow.Columns.Add(new DataGridViewTextBoxColumn { HeaderText = "Date", DataPropertyName = "Date", CellTemplate = new DataGridViewTextBoxCell() });
DataGridViewLinkColumn toComputer = new DataGridViewLinkColumn();
toComputer.HeaderText = "Status";
toComputer.Name = "link1";
toComputer.UseColumnTextForLinkValue = true;
toComputer.Text = "Save to File";
toComputer.ActiveLinkColor = Color.White;
toComputer.LinkColor = Color.Blue;
toComputer.TrackVisitedState = true;
toComputer.VisitedLinkColor = Color.Green;
dataGridViewShow.Columns.Add(toComputer);
dataGridViewShow.CellContentClick += (SaveFileType_click);
DataGridViewLinkColumn toNet = new DataGridViewLinkColumn();
toLinx.HeaderText = " ";
toLinx.Name = "link2";
toLinx.UseColumnTextForLinkValue = true;
toLinx.Text = "Send to Net";
toLinx.ActiveLinkColor = Color.White;
toLinx.LinkColor = Color.Blue;
toLinx.TrackVisitedState = true;
toLinx.VisitedLinkColor = Color.Green;
dataGridViewShow.Columns.Add(toNet);
dataGridViewShow.CellContentClick += ("Don't know how this gets handled");
上面的代码确实显示了两个不同的链接类型列,但是我不知道如何分别处理每个事件?
private void SaveFileType_click(object sender, DataGridViewCellEventArgs e)
{
selectedRow = e.RowIndex;
if (e.ColumnIndex == 0)
{
//some code goes here
}if (e.ColumnIndex == 1 && (string)dataGridViewShow[e.ColumnIndex, e.RowIndex].Value != "Complete")
{
//some code goes here
}
}