1
Vote

problem with nullable value in some rows

description

Hi,
 
very useful!
 
My list contains bool values (shown as checkboxes) and some null values.
 
Testing this list, i get this error: "Sequence contains no elements"
 
 
Here:
 
 
/// Calculate the header height of a DataGridView in a drawing surface,
/// it takes care only about visible columns
/// </summary>
/// <param name="dgv"></param>
/// <param name="g"></param>
/// <returns>DataGridView Columns Header Height</returns>
public static float HeaderHeight(this DataGridView dgv, Graphics g)
{
return (from
column in
dgv.Columns.OfType<DataGridViewColumn>()
where
column.Visible
select
g.MeasureString(
column.HeaderCell.EditedFormattedValue.ToString(),
column.HeaderCell.Font(),
column.HeaderCell.Size.Width).Height).
Max();
}
 
 
 
Thanks
Thomas
 
 
 
 
ok, what do you think we should do in this case? I want to say that we should not count when column.HeaderCell.EditedFormattedValue is null... Do you think it's what we should do?
 
Let's make code sharing our goal...
Blaise Braye
 
 
Changes:
 
public static float HeaderHeight(this DataGridView dgv, Graphics g)
{
if (dgv.RowCount == 0)
return 0;
...
 
We must check this at more than one position:
 
Next position to change ist here:
 
GridDrawer.cs:
// we have to set the first visible row outside of the loop
// cause we want to take care about the possible set Title block
int firstVisibleRowIndex = GridView.Rows.OfType<DataGridViewRow>()
.Where(row => row.Visible).First().Index;
 
Changes:
 
public void Initialize(Graphics g, DocumentMetrics metrics)
{
if (GridView.Rows.Count == 0)
return;
 
 
Or simple here:
 
public static PrintingDataGridViewProvider Create(PrintDocument printDocument,
DataGridView dgv, bool mustCenterPartition, bool mustFitColumnsToPage,
PrintBlock titlePrintBlock, PrintBlock sheetHeader, PrintBlock sheetFooter)
{
if (dgv.RowCount == 0)
return null; // ? -> Check outside to open the printdialog

comments