ConditionalFormattingObjects should be cleared or they should be applied after rebinding completes. WORKAROUND: save the ConditionalFormattingObjects, reset the data source and then restore them in order to overcome the observed error:
To reproduce: Add a RadGridView wth a few columns ,add rows as a few rows should have increasingly long text. Right click on the header cell to show the context menu and click bestfit. You will notice that the size of the column is not correct Workaround: void grid_MouseMove(object sender, MouseEventArgs e) { this.mouseLocation = e.Location; } private Point mouseLocation; private GridViewColumn currentColumn; void grid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) { if (this.grid.CurrentRow is GridViewHierarchyRowInfo) { RadItem bestFitItem = e.ContextMenu.Items.FirstOrDefault(x => x.Text == "Best Fit"); if (bestFitItem != null) { e.ContextMenu.Items.Remove(bestFitItem); } RadMenuItem newBestFitItem = new RadMenuItem { Text = "Best Fit" }; this.currentColumn = (this.grid.ElementTree.GetElementAtPoint(this.mouseLocation) as GridCellElement).ColumnInfo; newBestFitItem.Click += newBestFitItem_Click; e.ContextMenu.Items.Add(newBestFitItem); } } void newBestFitItem_Click(object sender, EventArgs e) { int highestWidth = this.GetHeightestWidthFromColumn(this.currentColumn); this.currentColumn.Width = highestWidth; } private int GetHeightestWidthFromColumn(GridViewColumn gridViewColumn) { int max = int.MinValue; Font cellFont = this.grid.TableElement.VisualRows[0].VisualCells[0].Font; for (int i = 0; i < this.grid.Rows.Count; i++) { int textWidth = TextRenderer.MeasureText(this.grid.Rows[i].Cells[gridViewColumn.Index].Value + "", cellFont).Width; if (max < textWidth) { max = textWidth; } } return max; }
To reproduce: - Add MultiColumnComboBoxColumn to a blank grid. - Subscribe to the SelectedIndexChanged event of the corresponding ActiveEditor (RadMultiColumnComboBoxElement). - You will notice that when you select different cells the event is fired several times.
To reproduce: - add RadGridView and populate manually with hierarchical data; - BestFitColumns method of the child template does not work as expected; #1 scenario: radGridView1.MasterTemplate.ExpandAll(); radGridView1.Templates[0].ExpandAll(); radGridView1.Templates[0].BestFitColumns(BestFitColumnMode.AllCells); You will notice that some of the columns in the child template are not wide enough to show the whole cell content; #2 scenario: Subscribe to the ChildViewExpanded event and call BestFitColumns: private void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) { e.ChildViewInfo.ViewTemplate.BestFitColumns(BestFitColumnMode.AllCells); } As a result the firstly expanded child view adjusts child template columns width and if you expand another child view which needs greater columns width, it is not displayed correctly. Workaround: determine the column width according to the longest cell content: foreach (GridViewDataColumn col in radGridView1.Templates[0].Columns) { BestFitAllCells(col); } private void BestFitAllCells(GridViewColumn column) { MasterGridViewTemplate masterTemplate = column.OwnerTemplate.Parent as MasterGridViewTemplate; if (masterTemplate == null) { return; } RadGridView grid = masterTemplate.Owner; IVirtualizedElementProvider<GridViewRowInfo> rowProvider = grid.TableElement.RowElementProvider; IVirtualizedElementProvider<GridViewColumn> cellProvider = grid.TableElement.ColumnScroller.ElementProvider; float width = 0; foreach (GridViewRowInfo dataRow in column.OwnerTemplate.Rows) { GridRowElement row = rowProvider.GetElement(dataRow, null) as GridRowElement; row.InitializeRowView(grid.TableElement); row.Initialize(dataRow); row.UpdateInfo(); grid.TableElement.Children.Add(row); row.ResetLayout(true); GridVirtualizedCellElement cell = cellProvider.GetElement(column, row) as GridVirtualizedCellElement; cell.Attach(column, row); cell.SetContent(); cell.UpdateInfo(); row.Children.Add(cell); GridHeaderCellElement headerCell = cell as GridHeaderCellElement; if (headerCell != null) { headerCell.UpdateArrowState(); } cell.ResetLayout(true); width = Math.Max(width, this.GetCellDesiredWidth(cell)); row.Children.Remove(cell); grid.TableElement.Children.Remove(row); this.Detach(cellProvider, cell); this.Detach(rowProvider, row); } width = Math.Max(width, TextRenderer.MeasureText(column.HeaderText, grid.Font).Width); column.Width = (int)width; } private float GetCellDesiredWidth(GridCellElement cell) { cell.Measure(new SizeF(float.PositiveInfinity, float.PositiveInfinity)); return cell.DesiredSize.Width; } private void Detach(IVirtualizedElementProvider<GridViewColumn> elementProvider, GridCellElement cell) { GridVirtualizedCellElement virtualizedCell = cell as GridVirtualizedCellElement; if (virtualizedCell != null) { elementProvider.CacheElement(virtualizedCell); virtualizedCell.Detach(); return; } cell.Dispose(); } private void Detach(IVirtualizedElementProvider<GridViewRowInfo> elementProvider, GridRowElement row) { GridVirtualizedRowElement virtualizedRоw = row as GridVirtualizedRowElement; if (virtualizedRоw != null) { elementProvider.CacheElement(virtualizedRоw); virtualizedRоw.Detach(); return; } row.Dispose(); }
To reproduce: - add RadGridView and populate it manually with hierarchical data; - open one row child rows and select several child rows; - right click to open the context menu and select Copy; - paste in Notepad for example. As a result there is no pasted data. Workaround: radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening; string clipBoard = string.Empty; RadGridView contextMenuInvoker; void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e) { RadGridView grid = sender as RadGridView; if (grid.CurrentCell is GridDataCellElement || grid.CurrentCell is GridTableBodyElement) { if (grid.CurrentRow.ViewTemplate != grid.MasterGridViewTemplate && !(grid.CurrentCell.RowInfo is GridViewNewRowInfo)) { RadMenuItem itemCopy = new RadMenuItem(); itemCopy.Text = "Copy Row(s)"; itemCopy.Click += new EventHandler(itemCopy_Click); e.ContextMenu.Items.RemoveAt(3); e.ContextMenu.Items.Insert(3, itemCopy); e.ContextMenu.Items.RemoveAt(4); } contextMenuInvoker = grid; } } void itemCopy_Click(object sender, EventArgs e) { CopyRows(contextMenuInvoker); } private void CopyRows(RadGridView radGridView) { StringBuilder sb = new StringBuilder(); foreach (GridViewRowInfo row in radGridView.SelectedRows) { int i = 0; while (i < row.Cells.Count) { if (i > 0) { sb.Append(","); } sb.Append(row.Cells[i].Value.ToString()); i++; } sb.AppendLine(";"); } clipBoard = sb.ToString(); Clipboard.SetDataObject(clipBoard); }
To reproduce: - add RadGridView with several columns and rows and export the grid to pdf file. - open the exported PDF file with Foxit Reader version 2.2. The opened file is blank.
To reproduce, copy a date time cell value and paste in excel.
To reproduce: Add a RadGridView with a ComboBoxColumn, add a datasource, use the following code on CellEditorInitializedEvent: void GridView_CellEditorInitialized(object sender, GridViewCellEventArgs e) { GridViewComboBoxColumn column = e.Column as GridViewComboBoxColumn; if (column != null) { RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor; if (editor != null) { RadDropDownListEditorElement editorElement = editor.EditorElement as RadDropDownListEditorElement; if (editorElement != null) { editorElement.AutoCompleteMode = AutoCompleteMode.SuggestAppend; } } } } Run the project, select a value from one of the dropdowns, start editing, press backspace, press the key which corresponds to the deleted character, for example if the last character was '2', press the key '2'. You will notice that the key will be ignored. Workaround: void GridView_CellEditorInitialized(object sender, GridViewCellEventArgs e) { GridViewComboBoxColumn column = e.Column as GridViewComboBoxColumn; if (column != null) { RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor; if (editor != null) { RadDropDownListEditorElement editorElement = editor.EditorElement as RadDropDownListEditorElement; editorElement.TextBox.KeyPress -= TextBox_KeyPress; editorElement.TextBox.KeyPress += TextBox_KeyPress; if (editorElement != null) { editorElement.AutoCompleteMode = AutoCompleteMode.SuggestAppend; } } } } private MethodInfo baseMethod = null; void TextBox_KeyPress(object sender, KeyPressEventArgs e) { if (char.IsLetterOrDigit(e.KeyChar)) { RadDropDownListEditorElement editorElement = ((this.GridView.ActiveEditor as RadDropDownListEditor).EditorElement as RadDropDownListEditorElement); MethodInfo method = baseMethod == null ? baseMethod = typeof(AutoCompleteAppendHelper).GetMethod("SetEditableElementText", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) : baseMethod; InvokeNotOverride(method, editorElement.AutoCompleteAppend, editorElement.AutoCompleteAppend.FindShortestString(editorElement.Text + e.KeyChar)); editorElement.TextBox.TextBoxItem.TextBoxControl.SelectionStart = editorElement.Text.Length; } } public object InvokeNotOverride(MethodInfo methodInfo, object targetObject, params object[] arguments) { var parameters = methodInfo.GetParameters(); if (parameters.Length == 0) { if (arguments != null && arguments.Length != 0) throw new Exception("Arguments cont doesn't match"); } else if (parameters.Length != arguments.Length) { throw new Exception("Arguments cont doesn't match"); } Type returnType = null; if (methodInfo.ReturnType != typeof(void)) { returnType = methodInfo.ReturnType; } var type = targetObject.GetType(); var dynamicMethod = new DynamicMethod("", returnType, new Type[] { type, typeof(Object) }, type); var iLGenerator = dynamicMethod.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Ldc_I4_S, i); iLGenerator.Emit(OpCodes.Ldelem_Ref); var parameterType = parameter.ParameterType; if (parameterType.IsPrimitive) { iLGenerator.Emit(OpCodes.Unbox_Any, parameterType); } else { iLGenerator.Emit(OpCodes.Castclass, parameterType); } } iLGenerator.Emit(OpCodes.Call, methodInfo); iLGenerator.Emit(OpCodes.Ret); return dynamicMethod.Invoke(null, new object[] { targetObject, arguments }); }
Workaround: add the option and the logic for it in the ContextMenuOpening event
To reproduce: -add RadDock with ToolWindow; -add RadGridView inside the ToolWindow; -apply Office2010Blue theme to the entire application; By default the GridDataCellElement has Font Segoe UI, 8.25pt with blue fore color. When the ToolWindow is floating, GridDataCellElement's font is changed to Microsoft Sans Serif, 8.25pt with black fore color. Workaround: customize the theme by setting the appropriate font and fore color to the GridDataCellElement for the necessary element states.
To reproduce: 1.Bind RadGridView to hierarchical data - no vertical scroll-bar is visible. 2.Select a certain row and expand the child template (click the expander) - vertical scroll-bar appears. 3.Scroll several rows downwards. 4.Click the expander to close the child template (the vertical scroll-bar should hide). As a result the selected row is changed. Workaround: follow the approach below: GridViewHierarchyRowInfo row = null; bool keepParentRow = false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.productsTableAdapter.Fill(this.nwindDataSet.Products); this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories); radGridView1.AutoGenerateHierarchy = true; radGridView1.DataSource = this.nwindDataSet; radGridView1.DataMember = "Categories"; radGridView1.CurrentRowChanging += radGridView1_CurrentRowChanging; radGridView1.ChildViewExpanded += radGridView1_ChildViewExpanded; radGridView1.MouseDown += radGridView1_MouseDown; } private void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e) { RadGridView grid = sender as RadGridView; if (grid != null && row != null && keepParentRow) { e.Cancel = true; } } private void radGridView1_MouseDown(object sender, MouseEventArgs e) { RadGridView grid = sender as RadGridView; if (grid != null) { GridExpanderItem expander = grid.ElementTree.GetElementAtPoint(e.Location) as GridExpanderItem; if (expander != null && row != null) { keepParentRow = true; } else { keepParentRow = false; } } } private void radGridView1_ChildViewExpanded(object sender, Telerik.WinControls.UI.ChildViewExpandedEventArgs e) { RadGridView grid = sender as RadGridView; if (grid != null && e.IsExpanded == false) { row = e.ParentRow as GridViewHierarchyRowInfo; } }
Description: use RadGridView with a lot of columns (e.g. 50) that the horizontal scroll-bar appears. When exporting to PDF, the columns should be rendered correctly like in RadGridView Multi-Page printing.
To reproduce: Dim RadGridView1 As New RadGridView Me.Controls.Add(RadGridView1) RadGridView1.Dock = DockStyle.Fill Dim r As New Random() Dim table As New DataTable() table.Columns.Add("ID", GetType(Integer))
To reproduce: -add RadGridView and apply Windows7 theme -click on some GridHeaderCellElement. As a result the arrow is cut off. Workaround: this.radGridView1.ViewCellFormatting+=radGridView1_ViewCellFormatting; private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) { GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement; if (cell != null) { cell.Arrow.Margin = new Padding(0, 3, 0, 0); } }
Description: hover the last row bottom border in such a way to display re-sizing cursor. Then move the cursor downwards. The problem occurs only when you have a few rows and move the cursor to the blank side of the grid view. To reproduce: -add RadGridView and use the following code: private void Form1_Load(object sender, EventArgs e) { this.customersTableAdapter.Fill(this.nwindDataSet.Customers); foreach (DataColumn column in this.nwindDataSet.Customers.Columns) { this.radGridView1.Columns.Add(column.ColumnName); } object[] row = this.nwindDataSet.Customers.Rows[0].ItemArray; this.radGridView1.Rows.Add(row); this.radGridView1.SelectedRows[0].IsSelected = false; this.radGridView1.CurrentCell.IsCurrent = false; this.radGridView1.CurrentRow.IsCurrent = false; } Workaround: public Form1() { InitializeComponent(); this.radGridView1.GridBehavior = new MyBaseBehavior(); } public class MyBaseBehavior : BaseGridBehavior { public override bool OnMouseMove(MouseEventArgs e) { GridRowElement currentRow = this.RowAtPoint; if (currentRow == null && e.Button == MouseButtons.None && Cursor.Current != Cursors.Default) { Cursor.Current = Cursors.Default; } return base.OnMouseMove(e); } }
To reproduce: -add RadGridView and enable excel-like filtering; -apply Windows7 theme When clicking on the filter button, the filter-dialog that shows is not really wide enough, it cuts the Cancel-button. Workaround: this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized; private void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e) { e.FilterPopup.PopupOpening -= FilterPopup_PopupOpening; e.FilterPopup.PopupOpening += FilterPopup_PopupOpening; } private void FilterPopup_PopupOpening(object sender, CancelEventArgs args) { RadListFilterPopup popup = sender as RadListFilterPopup; Padding currentPadding = popup.ButtonsMenuItem.Padding; popup.ButtonsMenuItem.Padding = new Padding(currentPadding.Left, currentPadding.Top, 20, currentPadding.Bottom); }
To reproduce: Add a GridViewImageColumn and set its FieldName to something that returns an empty string. You will notice that in the output window numerous first chance exceptions are being thrown.
To reproduce: -add RadGridView and RadButton to the form; -apply Office2010Black to the grid; -use the following code: private DataTable dataTable; public Form1() { InitializeComponent(); radGridView1.AutoSizeRows = false; radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.RowFormatting += radGridView1_RowFormatting; radGridView1.ReadOnly = true; radGridView1.ShowRowHeaderColumn = false; radGridView1.VerticalScrollState = ScrollState.AlwaysShow; radGridView1.ThemeName = "Office2010Black"; dataTable = new DataTable(); dataTable.Columns.Add("number", typeof(int)); dataTable.Columns.Add("descriptions", typeof(string)); radGridView1.DataSource = dataTable; } void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e) { e.RowElement.RowInfo.Height = 120; } private void radButton1_Click(object sender, EventArgs e) { radGridView1.Enabled = false; Random rnd = new Random((int)DateTime.Now.Ticks); dataTable.Clear(); for (int i = 0; i < rnd.Next(1000); i++) { DataRow row = dataTable.NewRow(); row[0] = i + 1; row[1] = "description" + i.ToString(); dataTable.Rows.Add(row); } radGridView1.Enabled = true; } After clicking the button, notice that the vertical scroll bar is not painted correctly and it is resized when scrolling. Workaround: Update the button Click event as follows: private void radButton1_Click(object sender, EventArgs e) { radGridView1.VerticalScrollState = ScrollState.AlwaysHide; radGridView1.Enabled = false; radGridView1.BeginEdit(); Random rnd = new Random((int)DateTime.Now.Ticks); dataTable.Clear(); for (int i = 0; i < rnd.Next(1000); i++) { DataRow row = dataTable.NewRow(); row[0] = i + 1; row[1] = "description" + i.ToString(); dataTable.Rows.Add(row); } radGridView1.EndEdit(); radGridView1.Enabled = true; radGridView1.VerticalScrollState = ScrollState.AlwaysShow; radGridView1.TableElement.VScrollBar.ResetLayout(true); radGridView1.MasterTemplate.Refresh(); radGridView1.TableElement.ScrollToRow(radGridView1.CurrentRow); }
To reproduce: public Form1() { InitializeComponent(); InitializeRadGridView(); this.Size = new System.Drawing.Size(782, 647); radGridView1.DataSource = GetDataSource(); radGridView1.MasterTemplate.ExpandAll(); } private void InitializeRadGridView() { radGridView1.EnableGrouping = false; radGridView1.AllowAddNewRow = false; radGridView1.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; GridViewDataColumn column = new GridViewTextBoxColumn(); column.FieldName = "Name"; radGridView1.MasterTemplate.Columns.Add(column); GridViewTemplate template = new GridViewTemplate(); template.AllowCellContextMenu = false; template.AllowColumnHeaderContextMenu = false; template.AutoGenerateColumns = false; template.ShowRowHeaderColumn = false; template.ShowColumnHeaders = false; template.AllowAddNewRow = false; template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.Templates.Add(template); GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate, template); relation.ChildColumnNames.Add("Bs"); radGridView1.Relations.Add(relation); column = new GridViewTextBoxColumn(); column.FieldName = "Name"; radGridView1.Templates[0].Columns.Add(column); column = new GridViewImageColumn(); column.MinWidth = column.MaxWidth = 30; radGridView1.Templates[0].Columns.Add(column); radGridView1.Templates[0].AllowRowReorder = true; template = new GridViewTemplate(); template.AllowCellContextMenu = false; template.AllowColumnHeaderContextMenu = false; template.AutoGenerateColumns = false; template.ShowRowHeaderColumn = false; template.ShowColumnHeaders = false; template.AllowAddNewRow = false; template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.Templates[0].Templates.Add(template); relation = new GridViewRelation(radGridView1.Templates[0], template); relation.ChildColumnNames.Add("Cs"); radGridView1.Relations.Add(relation); column = new GridViewTextBoxColumn(); column.FieldName = "Name"; radGridView1.Templates[0].Templates[0].Columns.Add(column); radGridView1.Templates[0].Templates[0].AllowRowReorder = true; } private List<A> GetDataSource() { List<A> list = new List<A>(); A a1 = new A(); a1.Id = 1; a1.Name = "A1"; list.Add(a1); A a2 = new A(); a2.Id = 2; a2.Name = "A2"; list.Add(a2); A a3 = new A(); a3.Id = 3; a3.Name = "A3"; list.Add(a3); B b1 = new B(); b1.Id = 10; b1.Name = "B1"; a1.Bs.Add(b1); B b2 = new B(); b2.Id = 20; b2.Name = "B2"; a1.Bs.Add(b2); B b3 = new B(); b3.Id = 30; b3.Name = "B3"; a1.Bs.Add(b3); B b4 = new B(); b4.Id = 40; b4.Name = "B4"; a2.Bs.Add(b4); B b5 = new B(); b5.Id = 50; b5.Name = "B5"; a3.Bs.Add(b5); C c1 = new C(); c1.Id = 100; c1.Name = "C1"; b1.Cs.Add(c1); b3.Cs.Add(c1); C c2 = new C(); c2.Id = 200; c2.Name = "C2"; b1.Cs.Add(c2); b2.Cs.Add(c2); b2.Cs.Add(c1); C c3 = new C(); c3.Id = 300; c3.Name = "C3"; b1.Cs.Add(c3); b2.Cs.Add(c3); b3.Cs.Add(c3); C c4 = new C(); c4.Id = 400; c4.Name = "C4"; b4.Cs.Add(c4); C c5 = new C(); c5.Id = 500; c5.Name = "C5"; b5.Cs.Add(c5); return list; } } public class A { public int Id { get; set; } public string Name { get; set; } public List<B> Bs { get; set; } public A() { Bs = new List<B>(); } } public class B { public int Id { get; set; } public string Name { get; set; } public List<C> Cs { get; set; } public B() { Cs = new List<C>(); } } public class C { public int Id { get; set; } public string Name { get; set; } } The last row is not fully visible, hence a scroll bar should be shown Workaround: collapse and expand the last row in the grid: radGridView1.MasterTemplate.ExpandAll(); radGridView1.ChildRows[radGridView1.ChildRows.Count - 1].IsExpanded = false; radGridView1.ChildRows[radGridView1.ChildRows.Count - 1].IsExpanded = true;
To Reproduce: - Add GridViewCalculatorColumn to a RadGridView. - When you begin edit a cell the value is not selected. Workaround: Create a custom RadCalculatorEditor and then change the editor in EditorRequired event: void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e) { if (e.EditorType.Name == "RadCalculatorEditor") { e.Editor = new CustomCalculatorEditor(); } } public class CustomCalculatorEditor : RadCalculatorEditor { public override void BeginEdit() { base.BeginEdit(); RadCalculatorDropDownElement editorElement = this.EditorElement as RadCalculatorDropDownElement; editorElement.EditorContentElement.TextBoxItem.SelectAll(); } }