PopulateSourceColumnsDataGridView()
{
AssertValid();
DataGridViewRowCollection oDataGridRows = dgvSourceColumns.Rows;
oDataGridRows.Clear();
// Attempt to get the non-empty range of the active worksheet of the
// selected source workbook.
Range oNonEmptyRange;
if ( !TryGetSourceWorkbookNonEmptyRange(out oNonEmptyRange) )
{
return;
}
Boolean bSourceColumnsHaveHeaders =
cbxSourceColumnsHaveHeaders.Checked;
// Get the first row and column of the non-empty range.
Range oFirstRow = oNonEmptyRange.get_Resize(1, Missing.Value);
Range oColumn = oNonEmptyRange.get_Resize(Missing.Value, 1);
Object [,] oFirstRowValues = ExcelUtil.GetRangeValues(oFirstRow);
Int32 iNonEmptyColumns = oNonEmptyRange.Columns.Count;
Int32 iColumnOneBased = oColumn.Column;
for (Int32 i = 1; i <= iNonEmptyColumns; i++, iColumnOneBased++)
{
String sColumnLetter = ExcelUtil.GetColumnLetter(
ExcelUtil.GetRangeAddress( (Range)oColumn.Cells[1, 1] ) );
// Get the value of the column's first cell, if there is one.
String sFirstCellValue;
if ( !ExcelUtil.TryGetNonEmptyStringFromCell(oFirstRowValues, 1,
i, out sFirstCellValue) )
{
sFirstCellValue = null;
}
String sItemText = GetSourceColumnItemText(sFirstCellValue,
sColumnLetter, bSourceColumnsHaveHeaders);
oDataGridRows.Add(new ObjectWithText(iColumnOneBased, sItemText),
false, false, false);
// Move to the next column.
oColumn = oColumn.get_Offset(0, 1);
}
}