To reproduce:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
DataTable dt = NewDt();
this.radGridView1.DataSource = dt;
var c = this.radGridView1.Columns["Calculted"] as GridViewDecimalColumn;
c.EnableExpressionEditor = true;
c.Expression = "Column2 / SUM(Column2) * 10";
c.DecimalPlaces = 2;
c.FormatString = "{0:N2}";
this.radGridView1.GroupDescriptors.Add("GroupByColumn", ListSortDirection.Ascending);
}
private DataTable NewDt()
{
var dt = new DataTable();
dt.Columns.Add("ItemColumn");
dt.Columns.Add("GroupByColumn");
dt.Columns.Add("Column2", typeof(decimal));
dt.Columns.Add("Calculted", typeof(decimal));
for (int i = 1; i <= 20; i++)
{
string gr = string.Empty;
if (i % 3 == 0)
gr = "gr3";
else if (i % 2 == 0)
gr = "gr2";
else if (i % 5 == 0)
gr = "gr5";
else
gr = "item" + i.ToString();
dt.Rows.Add("id #" + i.ToString(), gr, i, 0);
}
return dt;
}
Workaround:
public class CustomExpressionContext : Telerik.Data.Expressions.ExpressionContext
{
RadGridView radGridView;
public CustomExpressionContext(RadGridView grid)
{
this.radGridView = grid;
}
public decimal MySum(string columnName)
{
decimal sum = 0;
foreach (var item in radGridView.Rows)
{
sum += (decimal)item.Cells[columnName].Value;
}
return sum;
}
}
Telerik.Data.Expressions.ExpressionContext.Context = new CustomExpressionContext(this.radGridView1);
To reproduce: run the attached sample project. You will notice the result illustrated in the provided screenshot. Although the grid is RTL, the print preview dialog show it in LTR.
Workaround:
public class CustomGridPrintStyle : GridPrintStyle
{
protected override BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid)
{
if (this.PrintRenderer != null)
{
this.PrintRenderer.PrintCellPaint -= renderer_PrintCellPaint;
this.PrintRenderer.PrintCellFormatting -= renderer_PrintCellFormatting;
this.PrintRenderer.ChildViewPrinting -= renderer_ChildViewPrinting;
}
BaseGridPrintRenderer renderer = null;
if (grid.ViewDefinition.GetType() == typeof(ColumnGroupsViewDefinition))
{
if (!(renderer is ColumnGroupsViewDefinitionPrintRenderer))
{
renderer = new CustomColumnGroupsViewDefinitionPrintRenderer(grid);
}
}
else if (grid.ViewDefinition.GetType() == typeof(HtmlViewDefinition))
{
if (!(renderer is HtmlViewDefinitionPrintRenderer))
{
renderer = new HtmlViewDefinitionPrintRenderer(grid);
}
}
else
{
if (!(renderer is TableViewDefinitionPrintRenderer))
{
renderer = new TableViewDefinitionPrintRenderer(grid);
}
}
renderer.ChildViewPrinting += renderer_ChildViewPrinting;
renderer.PrintCellFormatting += renderer_PrintCellFormatting;
renderer.PrintCellPaint += renderer_PrintCellPaint;
return renderer;
}
private void renderer_PrintCellPaint(object sender, PrintCellPaintEventArgs e)
{
this.OnPrintCellPaint(sender, e);
}
private void renderer_PrintCellFormatting(object sender, PrintCellFormattingEventArgs e)
{
this.OnPrintCellFormatting(sender, e);
}
private void renderer_ChildViewPrinting(object sender, ChildViewPrintingEventArgs e)
{
this.OnChildViewPrinting(sender, e);
}
}
public class CustomColumnGroupsViewDefinitionPrintRenderer : ColumnGroupsViewDefinitionPrintRenderer
{
public CustomColumnGroupsViewDefinitionPrintRenderer(RadGridView grid) : base(grid)
{
}
protected override void PrintRow(GridViewRowInfo row, ColumnGroupRowLayout rowLayout, GridPrintSettings settings, int currentX, int currentY, Graphics graphics)
{
float scrollableColumnsOffset = 0f;
float rightPinnedColumnsOffset = 0f;
foreach (GridViewColumn col in rowLayout.RenderColumns)
{
if (col is GridViewRowHeaderColumn || col is GridViewIndentColumn)
{
continue;
}
float height = rowLayout.GetRowHeight(row);
RectangleF cellBounds = rowLayout.GetCorrectedColumnBounds(row, col, this.GridView.RightToLeft == RightToLeft.Yes,
new RectangleF(0f, 0f, rowLayout.DesiredSize.Width, height));
if (cellBounds == RectangleF.Empty)
{
continue;
}
if (col.PinPosition == PinnedColumnPosition.Left)
{
if (scrollableColumnsOffset < cellBounds.Right + rowLayout.Owner.CellSpacing)
{
scrollableColumnsOffset = cellBounds.Right + rowLayout.Owner.CellSpacing;
rightPinnedColumnsOffset = scrollableColumnsOffset;
}
}
else if (col.PinPosition == PinnedColumnPosition.None)
{
if (rightPinnedColumnsOffset < scrollableColumnsOffset + cellBounds.Right + rowLayout.Owner.CellSpacing)
{
rightPinnedColumnsOffset = scrollableColumnsOffset + cellBounds.Right + rowLayout.Owner.CellSpacing;
}
cellBounds.X += scrollableColumnsOffset;
}
else
{
cellBounds.X += rightPinnedColumnsOffset;
}
cellBounds.Offset(currentX, currentY);
GridViewCellInfo cell;
CellPrintElement printCell;
if (row is GridViewTableHeaderRowInfo)
{
cell = this.GridView.MasterView.TableHeaderRow.Cells[col.Name];
printCell = this.CreateHeaderCellPrintElement(col);
if (printCell.Font != settings.HeaderCellFont)
{
if (settings.HeaderCellFont != null)
{
printCell.Font = settings.HeaderCellFont;
}
else
{
settings.HeaderCellFont = printCell.Font;
}
}
}
else if (row is GridViewSummaryRowInfo)
{
GridViewSummaryRowInfo rowInfo = row as GridViewSummaryRowInfo;
cell = rowInfo.Cells[col.Name];
if (cell == null)
{
continue;
}
printCell = this.CreateSummaryCellPrintElement(cell);
if (printCell.Font != settings.SummaryCellFont)
{
if (settings.SummaryCellFont != null)
{
printCell.Font = settings.SummaryCellFont;
}
else
{
settings.SummaryCellFont = printCell.Font;
}
}
}
else
{
cell = row.Cells[col.Name];
if (cell == null)
{
continue;
}
if (col is GridViewImageColumn)
{
printCell = this.CreateImageCellPrintElement(cell);
}
else
{
printCell = this.CreateDataCellPrintElement(cell);
if (printCell.Font != settings.CellFont)
{
if (settings.CellFont != null)
{
printCell.Font = settings.CellFont;
}
else
{
settings.CellFont = printCell.Font;
}
}
}
}
printCell.TextPadding = this.GridView.PrintStyle.CellPadding;
printCell.RightToLeft = this.GridView.RightToLeft == RightToLeft.Yes;
Rectangle rect = new Rectangle((int)cellBounds.X, (int)cellBounds.Y, (int)cellBounds.Width, (int)cellBounds.Height);
PrintCellFormattingEventArgs formattEventArgs = new PrintCellFormattingEventArgs(row, col, printCell);
this.OnPrintCellFormatting(formattEventArgs);
formattEventArgs.PrintCell.Paint(graphics, rect);
PrintCellPaintEventArgs paintEventArgs = new PrintCellPaintEventArgs(graphics, row, col, rect);
this.OnPrintCellPaint(paintEventArgs);
}
}
}
private void radButton1_Click(object sender, EventArgs e)
{
CustomGridPrintStyle style = new CustomGridPrintStyle();
this.radGridView1.PrintStyle = style;
RadPrintDocument printDoc = new RadPrintDocument();
printDoc.Landscape = true;
printDoc.RightHeader = "Right Header";
printDoc.HeaderHeight = 100;
printDoc.AssociatedObject = this.radGridView1;
RadPrintPreviewDialog dialog = new RadPrintPreviewDialog(printDoc);
dialog.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width - 200, Screen.PrimaryScreen.Bounds.Height - 200);
dialog.SetZoom(0.80);
dialog.ShowDialog();
}
There should be a way for users to determine if a row passes a certain filter criteria without that affecting any data operations.
The selection mode should be as in Windows Explorer - when Control is pressed, one should be able to move the current row with the up/down arrow keys and when Space is pressed, the current row should be selected/deselected.
This implementation can be used for the time being:
public partial class Form1 : RadForm
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AddGridSimpleUnbound();
radGridView1.MultiSelect = true;
BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new MyRowBehavior());
radGridView1.GridViewElement.Navigator = new MyNavigator();
}
class MyNavigator : BaseGridNavigator
{
protected override bool DoMultiSelect(GridViewRowInfo oldRow, GridViewColumn oldColumn, GridViewRowInfo row, GridViewColumn column)
{
if (!this.IsShiftButtonPressed && this.IsControlButtonPressed && !this.IsMouseSelection)
{
return true;
}
return base.DoMultiSelect(oldRow, oldColumn, row, column);
}
}
class MyRowBehavior : GridDataRowBehavior
{
bool kbdSelection = false;
public override bool ProcessKeyPress(KeyPressEventArgs keys)
{
if (kbdSelection)
{
kbdSelection = false;
return true;
}
return base.ProcessKeyPress(keys);
}
public override bool ProcessKey(KeyEventArgs keys)
{
if (keys.KeyCode == Keys.Space && this.GridControl.MultiSelect && keys.Control)
{
this.GridControl.CurrentRow.IsSelected ^= true;
kbdSelection = true;
return false;
}
else
{
return base.ProcessKey(keys);
}
}
}
}
Similar property is already available in the property grid and tree view exporters.
To reproduce:
Sub New()
InitializeComponent()
Dim items As New List(Of WorkOrder)
For index = 1 To 56
items.Add(New WorkOrder(index, "Item" & index, 0))
Next
Dim rand As New Random
For index = 57 To 500
items.Add(New WorkOrder(index, "Item" & index, rand.Next(1, 56)))
Next
Me.RadGridView1.Relations.AddSelfReference(Me.RadGridView1.MasterTemplate, "Id", "ParentId")
Me.RadGridView1.DataSource = items
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Me.RadGridView1.EnablePaging = True
Me.RadGridView1.PageSize = 20
End Sub
Public Class WorkOrder
Private _id As Integer
Private _name As String
Private _parentId As Integer
Public Sub New(id As Integer, name As String, parentId As Integer)
Me._id = id
Me._name = name
Me._parentId = parentId
End Sub
Public Property Id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property ParentID() As Integer
Get
Return _parentId
End Get
Set(ByVal value As Integer)
_parentId = value
End Set
End Property
End Class
Workaround: use standard hierarchy: http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
Example : if we have 5 rows in the grid and if we copy 10 rows from excel and paste in first row, only first 5 records gets pasted and remaining 5 would be ignored.
It would be great if multi-page printing is supported for grids with ColumnGroupsViewDefinition and HtmlViewDefinition.
RadGridView, TextBoxColumn - add support for autocomplete.
There should be a way to fix the width of certain columns. Their width should remain the same while resizing the grid.
One should be able to create a relation in order to produce the following hierarchy:
public class MainObject
{
public ObservableCollection<LibraryObject> ListOfLibraryObjects { get; set; }
}
public class LibraryObject
{
public string LibraryName { get; set; }
public TrajectoryManager TheTrajectoryManager { get; set; }
}
public class TrajectoryManager
{
public ObservableCollection<TrajectoryData> ListOfTrajectoryData { get; set; }
}
public class TrajectoryData
{
public string Name { get; set; }
}
WORKAROUND:
public class MainObject
{
public ObservableCollection<LibraryObject> ListOfLibraryObjects;
}
public class LibraryObject
{
public string LibraryName { get; set; }
public ObservableCollection<TrajectoryData> ListOfTrajectoryData { get; set; }
// public TrajectoryManager TheTrajectoryManager;
//}
//public class TrajectoryManager
//{
// public ObservableCollection<TrajectoryData> ListOfTrajectoryData;
}
public class TrajectoryData
{
public string Name { get; set; }
}
Improve editors in RadGridView by allowing clipping when the control is scrolled.
ADD. RadGridView - add AutoSizeRows functionality in HtmlViewDefinition
Improve RadGridView API by allowing user to set styles for all rows and columns through styles as Microsoft DataGridView. Expose the following properties: - ColumnHeadersDefaultCellStyle - RowHeadersDefaultCellStyle - RowsDefaultCellStyle - DefaultCellStyle
Currently exporters do not respect the RightToLeft property of RadGridView and export the data always as left to right.
Add a TextAlignment property of GridViewSummaryItem.