There should be a way for users to determine if a row passes a certain filter criteria without that affecting any data operations.
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();
}
To reproduce, add menu item in the filtering context menu and upon click, set it as checked. Note that the filtering cell text should also take the custom menu item text or there should be an approach to set it.
Workaround: uncomment the commented code below.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AddGrid();
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 5; i++)
{
dt.Rows.Add(i, "Item" + i);
}
dt.Rows.Add(5, null);
dt.Rows.Add(6, "");
radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.EnableCustomFiltering = true;
//radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening;
}
private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
GridFilterCellElement filterCell = e.ContextMenuProvider as GridFilterCellElement;
GridViewDataColumn dataCol = (GridViewDataColumn)filterCell.ColumnInfo;
if (filterCell != null)
{
if (filterCell.ColumnInfo.Name == "Name")
{
RadMenuItem isNullMenuItem = new RadMenuItem();
isNullMenuItem.Click += customMenuItem_Click;
isNullMenuItem.Text = "My IsNull";
isNullMenuItem.Tag = filterCell.ColumnInfo.Name;
e.ContextMenu.Items.Add(isNullMenuItem);
RadMenuItem isNotNullMenuItem = new RadMenuItem();
isNotNullMenuItem.Click += customMenuItem_Click;
isNotNullMenuItem.Text = "My IsNotNull";
isNotNullMenuItem.Tag = filterCell.ColumnInfo.Name;
e.ContextMenu.Items.Add(isNotNullMenuItem);
bool isCustomFilter = (dataCol.FilterDescriptor != null &&
dataCol.FilterDescriptor is CompositeFilterDescriptor &&
dataCol.FilterDescriptor.Expression.Contains("NULL"));
foreach (RadMenuItem item in e.ContextMenu.Items)
{
if (item.Text == "Is null" || item.Text == "Is not null")
{
item.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
//if (isCustomFilter)
//{
// item.IsChecked = false;
//}
}
//if (isCustomFilter)
//{
// if (((CompositeFilterDescriptor)dataCol.FilterDescriptor).LogicalOperator == FilterLogicalOperator.And)
// {
// isNotNullMenuItem.IsChecked = true;
// }
// else
// {
// isNullMenuItem.IsChecked = true;
// }
//}
}
}
}
private void customMenuItem_Click(object sender, EventArgs e)
{
RadMenuItem clickedItem = (RadMenuItem)sender;
string columnName = clickedItem.Tag.ToString();
radGridView1.Columns[columnName].FilterDescriptor = null;
FilterOperator filterOperator = clickedItem.Text.Contains("Not") ? FilterOperator.IsNotEqualTo : FilterOperator.IsEqualTo;
FilterLogicalOperator logicalOperator = clickedItem.Text.Contains("Not") ? FilterLogicalOperator.And : FilterLogicalOperator.Or;
CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
compositeFilter.FilterDescriptors.Add(new FilterDescriptor(columnName, filterOperator, ""));
compositeFilter.FilterDescriptors.Add(new FilterDescriptor(columnName, filterOperator, null));
compositeFilter.LogicalOperator = logicalOperator;
compositeFilter.IsFilterEditor = true;
this.radGridView1.FilterDescriptors.Add(compositeFilter);
clickedItem.IsChecked = true;
}
To reproduce:
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("IsActive", typeof(bool));
dt.Rows.Add(1, "Parent1", false);
dt.Rows.Add(2, "Parent2", false);
this.radGridView1.DataSource = dt;
((GridViewCheckBoxColumn)this.radGridView1.MasterTemplate.Columns["IsActive"]).EnableHeaderCheckBox = true;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
DataTable childDataTable = new DataTable();
childDataTable.Columns.Add("Id", typeof(int));
childDataTable.Columns.Add("Title", typeof(string));
childDataTable.Columns.Add("ParentId", typeof(int));
childDataTable.Columns.Add("IsValid", typeof(bool));
childDataTable.Rows.Add(1, "Child 1", 1, false);
childDataTable.Rows.Add(2, "Child 1", 1, false);
childDataTable.Rows.Add(3, "Child 2", 2, false);
childDataTable.Rows.Add(4, "Child 2", 2, false);
GridViewTemplate template = new GridViewTemplate();
template.DataSource = childDataTable;
((GridViewCheckBoxColumn)template.Columns["IsValid"]).EnableHeaderCheckBox = true;
radGridView1.MasterTemplate.Templates.Add(template);
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "MasterDeatial";
relation.ParentColumnNames.Add("Id");
relation.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation);
Hello, we have a RadGridview with a number column and a activated filter for this Grid. If we want to filter data by the value "123" the input in the filter textBox is shown as "321.00" (right-to-left). This is no problem by columns with text values. And at the line for a new data row the input is correct, too.
To reproduce: please refer to the attached gif file and sample project.
Workaround: when you set the DrawFill property to true, specify the BackColor to the desired one and reset for the rest of the cells.
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.Column.Name == "ProductName" && e.Row is GridViewDataRowInfo)
{
if (e.CellElement.Value.ToString().Contains("C"))
{
e.CellElement.DrawFill = true;
e.CellElement.BackColor = Color.Yellow;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.ForeColor = Color.OliveDrab;
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
To reproduce: 1. Run the attached sample project. 2. Right-click the grid. 3. Quickly navigate to another application (e.g. Windows Explorer) before the context menu is shown & wait at windows explorer to display the menu 4. The context will be stuck.
To reproduce:
private void RadGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
int startIndex = radGridView1.CurrentRow.Index +1;
for (int i = startIndex; i < radGridView1.Rows.Count; i++)
{
var value = radGridView1.Rows[i].Cells["Name"].Value.ToString().ToLower();
if (value.StartsWith(e.KeyChar.ToString()))
{
radGridView1.TableElement.ScrollToRow(radGridView1.Rows[i]);
radGridView1.ClearSelection();
radGridView1.Rows[i].IsSelected = true;
radGridView1.Rows[i].IsCurrent = true;
radGridView1.Columns[1].IsCurrent = true;
break;
}
}
}
- Press some key so the grid is scrolled down, then press the down key.
- The first row is selected instead of the next one.
Workaround:
remove this line:
radGridView1.Rows[i].IsSelected = true;
To reproduce: please refer to the attached gif file.
Workaround:
public RadForm1()
{
InitializeComponent();
this.radGridView1.CellClick+=radGridView1_CellClick;
}
private void radGridView1_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.Column is Telerik.WinControls.UI.GridViewRowHeaderColumn)
{
this.radGridView1.CloseEditor();
}
}
To reproduce: 1. Bind RadGridView to the Northwind.Customers table. 2. Activate the editor for some of the cells from the CustomerID column. 3. Enter "ALFKI" which already exists. The DataError event is supposed to be fired in this case. If you set the GridViewDataErrorEventArgs.ThrowException argument to true the exception is supposed to be thrown. However, nothing happens. Please refer to the attached sample project.
Create a grid with more than 20 columns and add 5K rows for example. Maximize the form and try to scroll with mouse wheel. You will notice that the scrolling performance is worse compared to the normal state of the form with less visible visual elements. Workaround: this.radGridView1.EnableFastScrolling = true; and use the scrollbar's thumb Second workaround: use paging: https://docs.telerik.com/devtools/winforms/gridview/paging/overview Thus, you will display as many rows as possible to display on the screen per page. Instead of scrolling, you will navigate through pages.
Use the attached project to reproduce.
- Start the project and group by any column and export the grid.
- The same code works finme if the document is imported.
Workaround:
Edit the document after it is exported:
var provider = new XlsxFormatProvider();
var workbook = new Workbook();
using (var stream = File.OpenRead(@"D:\123.xlsx"))
{
workbook = provider.Import(stream);
}
PatternFill solidPatternFill = new PatternFill(PatternType.Solid, System.Windows.Media.Color.FromRgb(46, 204, 113), Colors.Transparent);
CellValueFormat textFormat = new CellValueFormat("@");
Worksheet sheet = workbook.ActiveWorksheet;
CellRange range = new CellRange(0, 0, 1, 4);
CellSelection header = sheet.Cells[range];
if (header.CanInsertOrRemove(range, ShiftType.Down))
{
header.Insert(InsertShiftType.Down);
}
header.Merge();
header.SetFormat(textFormat);
header.SetFontFamily(new ThemableFontFamily("Rockwell"));
header.SetFontSize(24);
header.SetHorizontalAlignment(Telerik.Windows.Documents.Spreadsheet.Model.RadHorizontalAlignment.Center);
header.SetVerticalAlignment(Telerik.Windows.Documents.Spreadsheet.Model.RadVerticalAlignment.Center);
header.SetFill(solidPatternFill);
header.SetValue("Test");
using (var stream = File.OpenWrite("result.xlsx"))
{
provider.Export(workbook, stream);
}
Process.Start("result.xlsx");
To reproduce: bind the grid to a DataTable where one of the columns doesn't allow null values. Try to add a new record by using the new row in the grid. Even though you specify default values in the DefaultValuesNeeded event, the error still occurs. Please refer to the attached sample project and gif file.
Workaround: handle the RadGridView.DataError event:
private void RadGridView1_DataError(object sender, Telerik.WinControls.UI.GridViewDataErrorEventArgs e)
{
if (e.Exception.ToString().Contains("does not allow nulls"))
{
e.Cancel = true;
}
}
How to reproduce:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.EditorRequired += RadGridView1_EditorRequired;
}
private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
if (this.radGridView1.CurrentColumn.Index == 0)
{
e.Editor = new RadTimePickerElement();
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < 20; i++)
{
DataRow r = dt.NewRow();
dt.Rows.Add(r);
}
return dt;
}
}
Workaround: the scenario is not completely valid as when handling the EditorRequiredEvent one should use the GridTimePickerEditor
1. Use the column`s EditorType property:
((GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).EditorType = GridViewDateTimeEditorType.TimePicker
2. Alternatively, handle the event this way:
private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
if (this.radGridView1.CurrentColumn.Index == 0)
{
e.Editor = new GridTimePickerEditor();
}
}
Use attached to reproduce.
Workaround:
class MyGridCheckBoxHeaderCellElement : GridCheckBoxHeaderCellElement
{
public MyGridCheckBoxHeaderCellElement(GridRowElement row, GridViewColumn col) : base(col, row)
{
}
bool suspenUpdate = false;
protected override void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
suspenUpdate = true;
base.checkbox_ToggleStateChanged(sender, args);
suspenUpdate = false;
}
protected override void SetCheckBoxState()
{
if (!suspenUpdate)
{
base.SetCheckBoxState();
}
}
}
private void RadGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.Column != null&& e.CellType == typeof(GridCheckBoxHeaderCellElement))
{
e.CellElement = new MyGridCheckBoxHeaderCellElement(e.Row, e.Column);
}
}
How to reproduce: check the attached project and video
To reproduce: this.radGridView1.SummaryRowsBottom.Insert(0, summaryRowItem2); this.radGridView1.SummaryRowsBottom.Move(2, 0); Workaround: Remove all items and add them back with a spesific order.
Use attached to reproduce. Workaround - Set the position at runtime. Me.radGridView1.MasterTemplate.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom
To reproduce:
Public Class RadForm1
Public RadGridView1 As RadGridView
Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
CreateGrid()
FormatGrid()
SetDataSource()
End Sub
Private Sub CreateGrid()
Try
RadGridView1 = New RadGridView
Me.Controls.Add(RadGridView1)
Catch ex As Exception
MessageBox.Show(Me, ex.Message)
End Try
End Sub
Private Sub FormatGrid()
Dim col As GridViewTextBoxColumn
With RadGridView1
col = New GridViewTextBoxColumn
With col
.FieldName = "FieldID"
'NOTE: Comment out NullValue = "" to prevent the unhandled exception
.NullValue = ""
End With
.Columns.Add(col)
End With
End Sub
Private Sub SetDataSource()
Dim table As DataTable = Nothing
Dim row As DataRow = Nothing
table = New DataTable("GridList")
table.Columns.Add("FieldID", GetType(System.Guid))
row = table.NewRow
row("FieldID") = Guid.Empty
table.Rows.Add(row)
RadGridView1.DataSource = table
End Sub
End Class
Workaround:
Comment this line
NullValue = ""