/// <summary> /// Hanlde column selection events from our DataGridView. Columns are selected or deselected /// by setting the UsageType. Ensure changes are made to the through the managed wrapper (design-time interface) /// so that changes are persisted or cancelled based on form result. /// </summary> /// <param name="sender">DataGridView</param> /// <param name="e">DataGridViewCellEventArgs</param> private void dgColumns_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex >= 0) { // Get current value and flip boolean to get new value bool newValue = !Convert.ToBoolean(dgColumns.CurrentCell.Value); // Get the virtual column to work with IDTSVirtualInputColumn100 virtualColumn = _virtualInput.VirtualInputColumnCollection[e.RowIndex]; try { // Set the column UsageType to indicate the column is selected or not if (newValue) { _designTimeComponent.SetUsageType(_input.ID, _virtualInput, virtualColumn.LineageID, DTSUsageType.UT_READWRITE); } else { _designTimeComponent.SetUsageType(_input.ID, _virtualInput, virtualColumn.LineageID, DTSUsageType.UT_IGNORED); } } catch (Exception ex) { // Catch any error from base class SetUsageType here. // Display simple error message from exception MessageBox.Show(ex.Message, "Invalid Column", MessageBoxButtons.OK, MessageBoxIcon.Error); // Rollback UI selection dgColumns.CancelEdit(); } } }