I have a three-column DataTable that contains data that I need to use in various ways. The data in this DataTable comes from an Exchange Web Services call. The first column contains a row counter, the second contains the calendar name, and the third contains the calendar ID (which is a gibberish-looking string).
Displaying the raw data in a DataGridView is straightforward. But I want the DataGridView's second column to be different: instead of showing the calendar ID, I want to show some text ("Copy"), which, when clicked, will copy the calendar ID to the user's clipboard. Ideally it'd be styled like a hyperlink so the user knows it's not just some text in a box. This can conceivably be done with a DataGridViewLinkColumn type with an event handler.
The piece I'm having trouble with is populating the rows.
The following code sets up the columns just fine. But it doesn't populate the rows.
private static DataGridView CreateCalendarGridView(DataTable calendarTable)
{
//Bind to the data source
var calendarGridView = new DataGridView();
//calendarGridView.AutoGenerateColumns = false;
calendarGridView.AutoSize = false;
calendarGridView.DataSource = calendarTable;
calendarGridView.ColumnHeadersVisible = true;
//Create counter column
var counterColumn = new DataGridViewTextBoxColumn();
counterColumn.DataPropertyName = COUNTER_COLUMN_NAME;
counterColumn.Name = COUNTER_COLUMN_NAME;
counterColumn.HeaderText = COUNTER_COLUMN_LABEL;
//Create the Calendar name column
var calendarNameColumn = new DataGridViewTextBoxColumn();
calendarNameColumn.DataPropertyName = CALENDAR_COLUMN_NAME;
calendarNameColumn.Name = CALENDAR_COLUMN_NAME;
calendarNameColumn.HeaderText = CALENDAR_COLUMN_LABEL;
//Create the Copy ID hyperlink column
var copyIdLinkColumn = new DataGridViewLinkColumn();
copyIdLinkColumn.DataPropertyName = ID_COLUMN_NAME;
copyIdLinkColumn.Name = ID_COLUMN_NAME;
copyIdLinkColumn.HeaderText = ID_COLUMN_NAME;
copyIdLinkColumn.UseColumnTextForLinkValue = false;
copyIdLinkColumn.TrackVisitedState = true;
copyIdLinkColumn.LinkColor = Color.Blue;
copyIdLinkColumn.VisitedLinkColor = Color.Purple;
copyIdLinkColumn.LinkBehavior = LinkBehavior.HoverUnderline;
copyIdLinkColumn.Text = "Copy";
copyIdLinkColumn.UseColumnTextForLinkValue = true;
calendarGridView.Columns.Add(counterColumn);
calendarGridView.Columns.Add(calendarNameColumn);
calendarGridView.Columns.Add(copyIdLinkColumn);
//I feel like I'm missing a foreach row in the DataTable which would
//create the row of cells, but I'm not sure, because isn't that the
//point of the calendarGridView.DataSource assignment above?
return calendarGridView;
}
I feel like if I could get the rows to fill, I could figure out how to change the behavior of the clickable third column.
What am I doing wrong?