Setting the FormatString of a column in the child template does not seem to take effect.
Workaround: handle the SortChanging and FilterChanging events and clear the search criteria from the search row. The stored search string can later be restored in the SortChanged and FilterChanged events string filter = string.Empty; private void RadGrid_FilterChanged(object sender, GridViewCollectionChangedEventArgs e) { this.radGrid.MasterView.TableSearchRow.Search(filter); } private void RadGrid_SortChanged(object sender, GridViewCollectionChangedEventArgs e) { this.radGrid.MasterView.TableSearchRow.Search(filter); } private void RadGrid_SortChanging(object sender, GridViewCollectionChangingEventArgs e) { this.filter = this.radGrid.MasterView.TableSearchRow.SearchCriteria; this.radGrid.MasterView.TableSearchRow.Search(null); } private void RadGrid_FilterChanging(object sender, GridViewCollectionChangingEventArgs e) { this.filter = this.radGrid.MasterView.TableSearchRow.SearchCriteria; this.radGrid.MasterView.TableSearchRow.Search(null); }
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: set Excel-like filter according to the online documentation: https://docs.telerik.com/devtools/winforms/gridview/filtering/setting-filters-programmatically-(composite-descriptors) this.radGridView1.DataSource = this.productsBindingSource; this.productsTableAdapter.Fill(this.nwindDataSet.Products); this.radGridView1.EnableFiltering = true; this.radGridView1.ShowHeaderCellButtons = true; var filterDescriptor = new FilterDescriptor(); filterDescriptor.PropertyName = "UnitsInStock"; filterDescriptor.Value = 101; filterDescriptor.Operator = FilterOperator.IsEqualTo; var filterDescriptor2 = new FilterDescriptor(); filterDescriptor2.PropertyName = "UnitsInStock"; filterDescriptor2.Value = 104; filterDescriptor2.Operator = FilterOperator.IsEqualTo; var cfd = new CompositeFilterDescriptor(); cfd.LogicalOperator = FilterLogicalOperator.Or; cfd.FilterDescriptors.Add(filterDescriptor); cfd.FilterDescriptors.Add(filterDescriptor2); cfd.IsFilterEditor = true; this.radGridView1.FilterDescriptors.Add(cfd); this.radGridView1.MasterTemplate.ExcelFilteredColumns.Add(this.radGridView1.Columns["UnitsInStock"]); You will notice that the filter popup contains all possible values for this column which is OK, but none of the nodes is checked. It is necessary the visible rows to be checked. Workaround: check the nodes programmatically when the popup is shown: private void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e) { RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup; if (popup!=null) { popup.Tag = e.Column.Name; popup.PopupOpened-=popup_PopupOpened; popup.PopupOpened+=popup_PopupOpened; } } private void popup_PopupOpened(object sender, EventArgs args) { RadListFilterPopup popup = sender as RadListFilterPopup; foreach (GridViewRowInfo row in this.radGridView1.ChildRows) { RadTreeNode node= popup.MenuTreeElement.TreeView.FindNodes(row.Cells[popup.Tag+""].Value.ToString()).FirstOrDefault(); if (node!=null) { node.Checked = true; } } }
To reproduce: run the attached sample project. Type "res" in the search box very very fast. You will notice that the results with starting with "re" are highlighted. Note: it is usually reproducible the first serahc after loading the form.
How to reproduce: public partial class RadForm1 : Telerik.WinControls.UI.RadForm { public RadForm1() { InitializeComponent(); this.radGridView1.DataSource = this.GetData(); this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; GridViewDecimalColumn decimalColumn = this.radGridView1.Columns[0] as GridViewDecimalColumn; decimalColumn.DecimalPlaces = 2; decimalColumn.FormatString = "{0:N2}"; decimalColumn.ExcelExportType = DisplayFormatType.Custom; decimalColumn.ExcelExportFormatString = "0.000"; } public object GridViewSpreaExport { get; private set; } private object GetData() { DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(double)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Bool", typeof(bool)); dt.Columns.Add("Date", typeof(DateTime)); for (int i = 0; i < 100; i++) { dt.Rows.Add(1.10 + i, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(i)); } return dt; } private void radButton1_Click(object sender, EventArgs e) { GridViewSpreadStreamExport spreadExporter = new GridViewSpreadStreamExport(this.radGridView1); spreadExporter.FileExportMode = FileExportMode.CreateOrOverrideFile; SpreadStreamExportRenderer renderer1 = new SpreadStreamExportRenderer(); spreadExporter.RunExportAsync(@"..\..\exported-stream.xlsx", renderer1); } } Workaround: Create a custom SpreadStreamExportRenderer public class CustomSpreadStreamExportRenderer : SpreadStreamExportRenderer { public override void SetCellValue(DataType dataType, object value) { switch (dataType) { case DataType.Number: this.SetNumberValue(value); break; case DataType.DateTime: this.SetDateTimeValue(value); break; case DataType.Boolean: this.SetBooleanValue(value); break; case DataType.Other: if (this.SetNumberValue(value)) { break; } if (this.SetDateTimeValue(value)) { break; } if (this.SetBooleanValue(value)) { break; } this.SetStringValue(value); break; case DataType.String: default: this.SetStringValue(value); break; } } }
To reproduce: private void MasterTemplate_ViewChanged(object sender, DataViewChangedEventArgs args) { if (args.Action == ViewChangedAction.ExpandedChanged) { } } Workaround: - Use the GroupExpanded event.
To reproduce: please refer to the attached gif file illustrating the steps how to reproduce the problem with the Demo application. Workaround: private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) { GridDataCellElement cell = e.CellElement as GridDataCellElement; if (cell != null) { if (cell.ContainsErrors) { cell.DrawBorder = true; cell.BorderBoxStyle = BorderBoxStyle.FourBorders; cell.BorderBottomColor = cell.BorderTopColor = cell.BorderRightShadowColor = cell.BorderLeftShadowColor = Color.Transparent; cell.BorderBottomShadowColor = cell.BorderTopShadowColor = cell.BorderRightColor = cell.BorderLeftColor = Color.Red; cell.BorderBottomWidth = cell.BorderTopWidth = cell.BorderRightWidth = cell.BorderLeftWidth = 1; cell.BorderDrawMode = BorderDrawModes.HorizontalOverVertical; cell.ZIndex = 2; } else { cell.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderBottomColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderTopColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderTopShadowColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderLeftWidthProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.BorderDrawModeProperty, ValueResetFlags.Local); cell.ResetValue(LightVisualElement.ZIndexProperty, ValueResetFlags.Local); } } }
Use attached to reproduce. This is not an issue. Performing Begin/End update disposes of all elements along with the globally declared item. You need to check if the item is disposed of: void ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) { if (menuItem.IsDisposed) { menuItem = new RadMenuItem(); menuItem.Text = "Custom menu item"; menuItem.Click += menuItem_Click; } e.ContextMenu.Items.Add(menuItem); }
To reproduce: please refer to the attached sample gif file. Note that it is important that the child template is bound at design time and the columns are automatically generated. Workaround: setup the ViewDefinition programmatically:
To reproduce: run the attached sample project. Type "chef" in the search box and then try to sort some of the columns. Click the header cell several times and as a result the exception will occur. Workaround: public class CustomGrid : RadGridView { public new object DataSource { get { return (object)base.DataSource; } set { GridViewSearchRowInfo.Cancel = true; Thread.Sleep(100); base.DataSource = null; this.EnableFiltering = false; base.DataSource = value; this.EnableFiltering = true; base.CurrentRow = null; } } }
Use attached project to reproduce! Another case is when the font size is changed from the settings dialog - in this case, the row height is not adjusted. Workaround: Use the following custom print style: class MyTableViewDefinitionPrintRenderer : TableViewDefinitionPrintRenderer { public MyTableViewDefinitionPrintRenderer(RadGridView grid) : base(grid) { } protected override int GetDataRowHeight(GridViewRowInfo row, TableViewRowLayoutBase rowLayout) { int result = base.GetDataRowHeight(row, rowLayout); int newHeight = 0; if (!(row is GridViewGroupRowInfo)) { foreach (GridViewColumn col in row.ViewTemplate.Columns) { if (col is GridViewRowHeaderColumn || col is GridViewIndentColumn || !col.IsVisible) { continue; } string value = row.Cells[col.Name].Value.ToString(); TableViewCellArrangeInfo info = ((TableViewRowLayout)rowLayout).LayoutImpl.GetArrangeInfo(col); float cellWidth = (float)info.CachedWidth; int currentHeight = TextRenderer.MeasureText(value, this.GridView.PrintStyle.CellFont, new Size((int)cellWidth, 0), TextFormatFlags.WordBreak).Height + this.GridView.Font.Height *4; newHeight = Math.Max(newHeight, currentHeight); } } return Math.Max(newHeight, result); } } class MyPrintStyle :GridPrintStyle { protected override BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid) { return new MyTableViewDefinitionPrintRenderer(grid); } }
To reproduce: run the attached sample project and click the 'export' button. The exported file fill be automatically opened. If you select several cells from the UnitPrice column you will see at the bottom that the cell values ' total is displayed. However, if you include the summary item's value in the selection its value is not taken into consideration. If you pay attention to the cell's format, it will be General instead of custom numeric one. Workaround: Private Sub spreadExporter_CellFormatting(sender As Object, e As Telerik.WinControls.Export.CellFormattingEventArgs) If e.GridRowInfoType = GetType(GridViewSummaryRowInfo) AndAlso e.GridCellInfo.ColumnInfo.Name = "DecimalColumn" Then Dim cellSelection As CellSelection = TryCast(e.CellSelection, CellSelection) Dim cellFormat As New CellValueFormat("### ### ###.00") If cellFormat IsNot Nothing Then cellSelection.SetValue(Decimal.Parse(cellSelection.GetValue().Value.RawValue.Replace(" ", ""))) cellSelection.SetFormat(cellFormat) End If End If End Sub
To reproduce, perform the following steps with the attached project: Step 1: Create Sample Database ============================== New (Sample1.db) Import Save Close Step 2: ====== Open (Sample1.db) Import Save Close Step 3: ====== New (Sample2.db) Import (Exception) Workaround: radGridView1.GridViewElement.Navigator = new MyNavigator(); class MyNavigator : BaseGridNavigator { public override bool SelectLastRow() { var enumerator = typeof(BaseGridNavigator).GetField("enumerator", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this) as GridTraverser; enumerator.Reset(); return base.SelectLastRow(); } }
To reproduce: DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("NumberAsShort", typeof(ushort)); for (int i = 0; i < 100; i++) { dt.Rows.Add(i, "Row" + i, i ); } this.radGridView1.DataSource = dt; Workaround: use the CellFormatting event https://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells
Workaround: adjust the cell/row spacing this.radGridView1.TableElement.CellSpacing = -2; this.radGridView1.TableElement.RowSpacing = -2;
Workaround: private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) { GridDataCellElement cell = e.CellElement as GridDataCellElement ; if (cell!=null && cell.SelfReferenceLayout!=null) { foreach (RadElement item in cell.SelfReferenceLayout.StackLayoutElement.Children) { if (!(item is GridTreeExpanderItem)) { item.Visibility = ElementVisibility.Collapsed; } else { item.Visibility = ElementVisibility.Visible; } } } }
To reproduce: run the attached sample project and press the "stream export" button. Workaround: use the GridViewSpreadExport https://docs.telerik.com/devtools/winforms/gridview/exporting-data/spread-export Dim spreadExporter As GridViewSpreadExport = New GridViewSpreadExport(RadGridView1) Dim exportRenderer As New SpreadExportRenderer() Dim fileName As String = "..\..\Export" & DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx" spreadExporter.RunExport(fileName, exportRenderer)