Virtual row height
Brought to you by:
davideicardi
it's impossible to set height for a specific virtual row. Rows.SetHeight uses one value for all rows (RowHeight). so, it's pretty much unusable. I wanted to hide certain row when data source is a data table. couldn't. here's a simple code to fix this to work correctly.
replace RowsSimpleBase.GetHeight & SetHeight with this:
private readonly Dictionary< int, int > _heights = new Dictionary< int, int >();
public void ResetHeights()
{
_heights.Clear();
}
public override int GetHeight(int row)
{
if( _heights.ContainsKey( row ))
{
return _heights[ row ];
}
else
{
return RowHeight;
}
}
public override void SetHeight(int row, int height)
{
_heights[ row ] = height;
}
if there's a better way, I'd like to know about it
Logged In: YES
user_id=459824
Originator: NO
Great! :) It works like a charm :) You just saved my day :) Thank you so much
public abstract class RowsSimpleBase : RowsBase
{
private readonly Dictionary<int, int> mRowHeights = new Dictionary<int,int>();
/// <summary>
/// Initializes a new instance of the <see cref="RowsSimpleBase"/> class.
/// </summary>
/// <param name="grid">The grid.</param>
public RowsSimpleBase(GridVirtual grid):base(grid)
{
mRowHeight = grid.DefaultHeight;
}
private int mRowHeight;
/// <summary>
/// Gets or sets the height of the row.
/// </summary>
/// <value>The height of the row.</value>
public int RowHeight
{
get{return mRowHeight;}
set
{
if (mRowHeight != value)
{
mRowHeight = value;
PerformLayout();
}
}
}
/// <summary>
/// Gets the height of the specified row.
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
public override int GetHeight(int row)
{
if (this.mRowHeights.ContainsKey(row))
return this.mRowHeights[row];
else
return RowHeight;
}
/// <summary>
/// Sets the height of the specified row.
/// </summary>
/// <param name="row"></param>
/// <param name="height"></param>
public override void SetHeight(int row, int height)
{
this.mRowHeights[row] = height;
PerformLayout();
}
}