0
如果是這樣,我們如何分別處理cellcontentclick事件?我正在動態添加列。繼承人我的代碼: -
dataGridViewShow.Columns.Add(new DataGridViewTextBoxColumn { HeaderText = "Date", DataPropertyName = "Date", CellTemplate = new DataGridViewTextBoxCell() });
datagridview中可以有兩個不同類型的鏈接列嗎?
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
}
}
它的確幫助了謝謝。 – smons 2013-04-08 21:17:24