To reproduce: public RadForm1() { InitializeComponent(); Controls.Add(new RadGridView { Dock = DockStyle.Fill, ShowHeaderCellButtons = true, ReadOnly = true, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill, EnableFiltering = true, DataSource = Enumerable.Range(0, 24000) //Increase this number when you can't reproduce this issue .Select(x => new { Name = string.Format("Item {0}", x) }), }); } Workaround: class MyListFillter : RadListFilterPopup { public MyListFillter(GridViewDataColumn column, bool groupDateValues) : base(column, groupDateValues) { } protected override void OnButtonOkClick(EventArgs e) { FilterOperator filterOperator = FilterOperator.IsEqualTo; var listFilterElement = typeof(RadListFilterPopup).GetField("listFilterElement", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this) as FilterMenuTreeElement; switch (listFilterElement.SelectedMode) { case ListFilterSelectedMode.All: filterOperator = FilterOperator.None; break; case ListFilterSelectedMode.Null: filterOperator = FilterOperator.IsNull; break; case ListFilterSelectedMode.NotNull: filterOperator = FilterOperator.IsNotNull; break; } if (filterOperator != FilterOperator.IsEqualTo) { SetFilterOperator(filterOperator); this.ClosePopup(RadPopupCloseReason.CloseCalled); } else { CompositeFilterDescriptor compositeFilterDescriptor = new CompositeFilterDescriptor(); compositeFilterDescriptor.PropertyName = base.DataColumn.Name; compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.Or; if (listFilterElement.SelectedValues.Count > this.GetDistinctValuesTable().Count / 2) { foreach (DictionaryEntry entry in this.GetDistinctValuesTable()) { if (!listFilterElement.SelectedValues.Contains(entry.Key)) { foreach (object value in (ArrayList)entry.Value) { FilterDescriptor descriptor; if (base.DataColumn is GridViewDateTimeColumn || base.DataColumn.DataType == typeof(DateTime) || base.DataColumn.DataType == typeof(DateTime?)) { descriptor = new DateFilterDescriptor(base.DataColumn.Name, FilterOperator.IsNotEqualTo, (DateTime?)value, false); } else { descriptor = new FilterDescriptor(base.DataColumn.Name, FilterOperator.IsNotEqualTo, value); } compositeFilterDescriptor.FilterDescriptors.Add(descriptor); } } } } else { foreach (DictionaryEntry entry in listFilterElement.SelectedValues) { foreach (object value in (ArrayList)entry.Value) { FilterDescriptor descriptor; if (base.DataColumn is GridViewDateTimeColumn || base.DataColumn.DataType == typeof(DateTime) || base.DataColumn.DataType == typeof(DateTime?)) { descriptor = new DateFilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, (DateTime?)value, false); } else { descriptor = new FilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, value); } compositeFilterDescriptor.FilterDescriptors.Add(descriptor); } } } base.FilterDescriptor = compositeFilterDescriptor; OnFilterConfirmed(); } } }
To reproduce: - Bind the grid to a data source and set its RightToLeftProperty to true. Note: use Visual Studio 2008 under Windows XP with .NET 2.0 Workaround: Private Sub RadGridView1_ViewCellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) If RadGridView1.RightToLeft = Windows.Forms.RightToLeft.Yes Then e.CellElement.TextAlignment = ContentAlignment.MiddleLeft End If End Sub
To reproduce: - Add grid with a DateTime column with default value "5/1/2014"; - Start the app and press the following keys one after another: 5/1/ - You will notice that the "1" is not replaced. Please note that the similar behavior occur when the year is entered (it does not match the default one). Workaround handle the key press for such cases manually: void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) { RadDateTimeEditor ed = e.ActiveEditor as RadDateTimeEditor; RadDateTimeEditorElement el = ed.EditorElement as RadDateTimeEditorElement; el.KeyPress += el_KeyPress; } private void el_KeyPress(object sender, KeyPressEventArgs e) { RadDateTimeEditorElement el = (RadDateTimeEditorElement)sender; int day = el.Value.Value.Day; int key = -1; int.TryParse(e.KeyChar.ToString(), key); RadMaskedEditBoxElement element = el.TextBoxElement.TextBoxItem.Parent as RadMaskedEditBoxElement; MaskDateTimeProvider provider = element.Provider as MaskDateTimeProvider; if (provider.SelectedItemIndex == 2) { if (key > 0 & key <= 9) { if (el.TextBoxElement.TextBoxItem.SelectionLength != 0) { if (!booKeying) { dynamic NewValue = new DateTime(el.Value.Value.Year, el.Value.Value.Month, key); el.Value = NewValue; e.Handled = true; booKeying = true; } } } } }
Workaround: check for the theme and set a minimum size to the text box item private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e) { BaseGridEditor gridEditor = e.ActiveEditor as BaseGridEditor; if (gridEditor != null) { RadTextBoxElement el = gridEditor.OwnerElement.FindDescendant<RadTextBoxElement>(); if (el != null) { if (ThemeResolutionService.ApplicationThemeName == "VisualStudio2012Dark") { el.TextBoxItem.MinSize = new Size(0, 20); el.TextBoxItem.TextBoxControl.MinimumSize = new Size(0, 20); } } } }
To reproduce: protected override void OnLoad(EventArgs e) { this.radGridView1.AllowAddNewRow = false; this.radGridView1.TableElement.RowHeight = 40; this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; GridViewTextBoxColumn id = new GridViewTextBoxColumn("ID"); id.IsVisible = false; GridViewTextBoxColumn parentID = new GridViewTextBoxColumn("ParentID"); parentID.IsVisible = false; GridViewTextBoxColumn name = new GridViewTextBoxColumn("Name"); GridViewDateTimeColumn date = new GridViewDateTimeColumn("Date"); GridViewTextBoxColumn type = new GridViewTextBoxColumn("Type"); GridViewTextBoxColumn size = new GridViewTextBoxColumn("Size"); size.FormatString = "{0} MB"; radGridView1.Columns.AddRange(new GridViewDataColumn[] { id, parentID, name, date, type, size }); this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "ID", "ParentID"); radGridView1.CellValueChanged += radGridView1_CellValueChanged; fillData(); } void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e) { fillData(); } private void fillData() { radGridView1.Rows.Clear(); radGridView1.Rows.Add(1, null, "Program Files", DateTime.Now.AddDays(-100), "Folder", 5120); radGridView1.Rows.Add(2, 1, "Visual Studio 2010", DateTime.Now.AddDays(-100), "Folder", 3220); radGridView1.Rows.Add(3, 2, "bin", DateTime.Now.AddDays(-100), "Folder", 3220); radGridView1.Rows.Add(4, 2, "READEME.txt", DateTime.Now.AddDays(-100), "Text Document", 3); radGridView1.Rows.Add(100, null, "Test.txt", DateTime.Now.AddDays(-10), "Text File", 0); radGridView1.Rows.Add(5, 1, "Telerik RadControls", DateTime.Now.AddDays(-10), "Folder", 3120); radGridView1.Rows.Add(6, 5, "Telerik UI for Winforms", DateTime.Now.AddDays(-10), "Folder", 101); radGridView1.Rows.Add(7, 5, "Telerik UI for Silverlight", DateTime.Now.AddDays(-10), "Folder", 123); radGridView1.Rows.Add(8, 5, "Telerik UI for WPF", DateTime.Now.AddDays(-10), "Folder", 221); radGridView1.Rows.Add(9, 5, "Telerik UI for ASP.NET AJAX", DateTime.Now.AddDays(-10), "Folder", 121); radGridView1.Rows.Add(10, 1, "Microsoft Office 2010", DateTime.Now.AddDays(-120), "Folder", 1230); radGridView1.Rows.Add(11, 10, "Microsoft Word 2010", DateTime.Now.AddDays(-120), "Folder", 1230); radGridView1.Rows.Add(12, 10, "Microsoft Excel 2010", DateTime.Now.AddDays(-120), "Folder", 1230); radGridView1.Rows.Add(13, 10, "Microsoft Powerpoint 2010", DateTime.Now.AddDays(-120), "Folder", 1230); radGridView1.Rows.Add(14, 1, "Debug Diagnostic Tools v1.0", DateTime.Now.AddDays(-400), "Folder", 2120); radGridView1.Rows.Add(15, 1, "Designer's 3D Tools", DateTime.Now.AddDays(-500), "Folder", 1120); radGridView1.Rows.Add(16, 1, "Communication", DateTime.Now.AddDays(-700), "Folder", 120); } Then start the application edit a value and click another cell. Workaround: - Enclose the rows addition within Begin/End update block.
To reproduce: 1 - Add a grid view in a form. 2 - Add 14 - 17 records in grid view. 3 - Allow alternating color for grid view. 4 - Do sorting by clicking on header column (click 3 times). 5 - Alternating color display wrong position. Workaround: void radGridView1_SortChanged(object sender, GridViewCollectionChangedEventArgs e) { foreach (GridRowElement row in this.radGridView1.TableElement.ViewElement.ScrollableRows.Children) { row.Synchronize(); } }
Use the following code snippet: public Form1() { InitializeComponent(); DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Item", typeof(string)); dt.Columns.Add("Price", typeof(decimal)); for (int i = 0; i < 10; i++) { dt.Rows.Add(i % 5, "Item" + i, i * 2.25m); } this.radGridView1.DataSource = dt; GridViewDecimalColumn customCalculatedCol = new GridViewDecimalColumn("Custom Calculated Column"); customCalculatedCol.Name = "Custom Calculated Column"; customCalculatedCol.Expression = "SumIf(Id)"; radGridView1.Columns.Add(customCalculatedCol); GridViewDecimalColumn customCalculatedCola = new GridViewDecimalColumn("Custom Col_A"); radGridView1.Columns.Add(customCalculatedCola); this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; Telerik.Data.Expressions.ExpressionContext.Context = new CustomExpressionContext(radGridView1); } public class CustomExpressionContext : Telerik.Data.Expressions.ExpressionContext { private RadGridView grid; public CustomExpressionContext(RadGridView grid) { this.grid = grid; } public double SumIf(int currentId) { double countIf = 0; decimal sumIf = 0; foreach (GridViewRowInfo r in this.grid.Rows) { if ((int)r.Cells["Id"].Value == currentId) { countIf++; sumIf += (decimal)r.Cells["Price"].Value; } } return (double)sumIf; } } Workaround: invalidate the affected rows manually private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e) { if (e.Column.Name == "Price" || e.Column.Name == "Id") { foreach (GridViewRowInfo r in this.radGridView1.Rows) { if ((int)r.Cells["Id"].Value == (int)e.Row.Cells["Id"].Value) { r.InvalidateRow(); } } } }
To reproduce: - Use this code: private void Form1_Load(object sender, EventArgs e) { CenterToParent(); radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized; GridViewTextBoxColumn columnName = new GridViewTextBoxColumn(); columnName.Name = "Name"; columnName.HeaderText = "Name"; columnName.FieldName = "Name"; columnName.MaxLength = 50; columnName.Width = 200; columnName.TextAlignment = ContentAlignment.MiddleLeft; radGridView1.MasterTemplate.Columns.Add(columnName); GridViewDateTimeColumn columnDate = new GridViewDateTimeColumn(); columnDate.Name = "Date"; columnDate.HeaderText = "Date"; columnDate.FieldName = "Date"; columnDate.Format = DateTimePickerFormat.Custom; columnDate.CustomFormat = "MM/dd/yyyy"; columnDate.FormatString = "{0:MM/dd/yyyy}"; columnDate.NullValue = null; columnDate.Width = 100; this.radGridView1.Columns.Add(columnDate); radGridView1.Rows.Add("Row 1", null); radGridView1.Rows.Add("Row 2", null); radGridView1.Rows.Add("Row 3", null); radGridView1.Rows.Add("Row 4", null); } void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) { if (e.ActiveEditor is RadDateTimeEditor) { ((RadDateTimePickerElement)((RadDateTimeEditor)e.ActiveEditor).EditorElement).TextBoxElement.MaskType = MaskType.FreeFormDateTime; } } - Start the application and star edition date time value. You will notice that the editor value is initialized incorrectly. This occurs only when the cell is edited for the firs time. Workaround: void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) { if (e.ActiveEditor is RadDateTimeEditor) { ((RadDateTimePickerElement)((RadDateTimeEditor)e.ActiveEditor).EditorElement).TextBoxElement.MaskType = MaskType.FreeFormDateTime; e.ActiveEditor.Value = radGridView1.CurrentCell.Value; } }
To reproduce: 1. Add a RadGridView and bind it to Northwind.Products table. 2. Use the following code: Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products) For Each col As GridViewColumn In Me.RadGridView1.Columns If Not col.HeaderText = "SupplierID" AndAlso Not col.HeaderText = "ProductID" Then col.ReadOnly = True End If Next Me.RadGridView1.AddNewRowPosition = SystemRowPosition.Bottom End Sub Private Sub RadGridView1_CellValidating(sender As Object, e As CellValidatingEventArgs) Handles RadGridView1.CellValidating If e.Value Is Nothing Then If MessageBox.Show("Incorrect", "error", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then e.Cancel = True End If End If End Sub 3. Run the project and go to the new row ,cell "SupplierID". 4. Clear the value and press Tab key. As a result the message box for error indication is shown twice. Workaround: 'register the custom row behavior Dim gridBehavior As BaseGridBehavior = TryCast(RadGridView1.GridBehavior, BaseGridBehavior) gridBehavior.UnregisterBehavior(GetType(GridViewNewRowInfo)) gridBehavior.RegisterBehavior(GetType(GridViewNewRowInfo), New MyNewRowBehavior()) Me.RadGridView1.GridViewElement.Navigator = New MyGridNavigator() Public Class MyNewRowBehavior Inherits GridNewRowBehavior Protected Overrides Function ProcessTabKey(keys As KeyEventArgs) As Boolean If Me.GridControl.AddNewRowPosition = SystemRowPosition.Bottom AndAlso _ Me.GridControl.IsInEditMode AndAlso Me.GridViewElement.Navigator.IsLastColumn(GridViewElement.CurrentColumn) Then Me.GridControl.Tag = "SuspendValidation" End If Return MyBase.ProcessTabKey(keys) End Function End Class Public Class MyGridNavigator Inherits BaseGridNavigator Public Overrides Function SelectFirstColumn() As Boolean If Me.GridViewElement.GridControl.Tag = "SuspendValidation" Then Me.GridViewElement.GridControl.Tag = Nothing Return False End If Return MyBase.SelectFirstColumn() End Function End Class
To reproduce: use the attached sample project. Follow the steps illustrated on the attached gif file. Workaround: keep the vertical scrollbar value and maximum before modifying the child rows and restore them afterwards: private void gridViewParameter_CellValueChanged(object sender, GridViewCellEventArgs e) { if (e.Column.Name == "Select") { this.gridViewParameter.CellValueChanged -= gridViewParameter_CellValueChanged; GridViewRowInfo selectedRowinfo = e.Row; if (selectedRowinfo.HasChildRows()) { int scrollValue = this.gridViewParameter.TableElement.VScrollBar.Value; int scrollMax = this.gridViewParameter.TableElement.VScrollBar.Maximum; this._UpdateUiState(selectedRowinfo.ChildRows, Convert.ToBoolean(selectedRowinfo.Cells["Select"].Value)); this.gridViewParameter.TableElement.VScrollBar.Maximum = scrollMax; this.gridViewParameter.TableElement.VScrollBar.Value = scrollValue; } this.gridViewParameter.CellValueChanged += gridViewParameter_CellValueChanged; } } NOTE: after applying the workaround, there is annoying flickering illustrated on the Flickering.gif file which should be handled if possible.
To reproduce: - Create a hierarchy and set the UseScrollbarsInHierarchy property to true. - Scroll by pressing the thumb in the child template. - The CellClick event is fired when the mouse is released. Workaround: void radGridView1_CellClick(object sender, GridViewCellEventArgs e) { if (e.Column != null) { Console.WriteLine("CellClick"); } }
The idea is that one can bring into view a certain row.
To reproduce: Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products) Dim menu As New ContextMenu() For index = 1 To 4 menu.MenuItems.Add("item" & index) Next Me.ContextMenu = menu End Sub Workaround: Const WM_CONTEXTMENU As Integer = &H7B Public Class Grid Inherits RadGridView Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = WM_CONTEXTMENU Then Return End If MyBase.WndProc(m) End Sub Public Overrides Property ThemeClassName As String Get Return GetType(RadGridView).FullName End Get Set(value As String) MyBase.ThemeClassName = value End Set End Property End Class
Workaround this.radGridView1.Templates["MyEmptyTemplate"]..AddNewRowPosition = SystemRowPosition.Top Then handle the ViewCellFormatting event and get notifications when the hierarchy tabs are being clicked. private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) { GridDetailViewCellElement detailCell = e.CellElement as GridDetailViewCellElement; if (detailCell != null) { detailCell.PageViewElement.ItemSelected -= PageViewElement_ItemSelected; detailCell.PageViewElement.ItemSelected += PageViewElement_ItemSelected; } } private void PageViewElement_ItemSelected(object sender, RadPageViewItemSelectedEventArgs e) { if (e.SelectedItem.Text == "MyEmptyTemplate") { this.SetsGridViewTemplate.AddNewRowPosition = SystemRowPosition.Bottom; } }
To reproduce: - Add ColumnGroupsViewDefinition and subscribe to ColumnWidthChanged event. - Start the application and resize a column. Workaround: public class MyColumnGroupRowLayout : ColumnGroupRowLayout { public MyColumnGroupRowLayout(ColumnGroupsViewDefinition view) : base(view) { } public override void ResizeColumn(int delta) { base.ResizeColumn(delta); //This method will be called when a column is resized } } class MyColumnGroupsViewDefinition : ColumnGroupsViewDefinition { public override IGridRowLayout CreateRowLayout() { return new MyColumnGroupRowLayout(this); } }
To reproduce: for (int i = 0; i < 5; i++) { this.radGridView1.Columns.Add("Col" + i); } ColumnGroupsViewDefinition columnGroupsView = new ColumnGroupsViewDefinition(); columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup()); columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup()); columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup()); columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup()); columnGroupsView.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow()); columnGroupsView.ColumnGroups[0].Rows[0].ColumnNames.Add("Col3"); columnGroupsView.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow()); columnGroupsView.ColumnGroups[1].Rows[0].ColumnNames.Add("Col2"); columnGroupsView.ColumnGroups[2].Rows.Add(new GridViewColumnGroupRow()); columnGroupsView.ColumnGroups[2].Rows.Add(new GridViewColumnGroupRow()); columnGroupsView.ColumnGroups[2].Rows[0].ColumnNames.Add("Col0"); columnGroupsView.ColumnGroups[2].Rows[1].ColumnNames.Add("Col1"); columnGroupsView.ColumnGroups[3].Rows.Add(new GridViewColumnGroupRow()); columnGroupsView.ColumnGroups[3].Rows[0].ColumnNames.Add("Col4"); this.radGridView1.ViewDefinition = columnGroupsView; this.radGridView1.Columns["Col2"].Width = 150; this.radGridView1.Columns["Col0"].Width = 200; Workaround: either set the columns width before setting the RadGridView.ViewDefinition or call the TableElement.ViewElement.RowLayout.InvalidateRenderColumn after specifying the width.
To reproduce: private void Form1_Load(object sender, EventArgs e) { this.productsTableAdapter.Fill(this.nwindDataSet.Products); this.radGridView1.DataSource = this.productsBindingSource; GridViewSummaryItem summaryItem = new GridViewSummaryItem(); summaryItem.Name = "UnitPrice"; summaryItem.Aggregate = GridAggregateFunction.Count; GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem(); summaryRowItem.Add(summaryItem); this.radGridView1.SummaryRowsTop.Add(summaryRowItem); GroupDescriptor descriptor1 = new GroupDescriptor(); descriptor1.GroupNames.Add("CategoryID", ListSortDirection.Ascending); this.radGridView1.GroupDescriptors.Add(descriptor1); GroupDescriptor descriptor11 = new GroupDescriptor(); descriptor11.GroupNames.Add("SupplierID", ListSortDirection.Ascending); this.radGridView1.GroupDescriptors.Add(descriptor11); GroupDescriptor descriptor2 = new GroupDescriptor(); descriptor2.GroupNames.Add("QuantityPerUnit", ListSortDirection.Ascending); descriptor2.GroupNames.Add("UnitsInStock", ListSortDirection.Ascending); this.radGridView1.GroupDescriptors.Add(descriptor2); GroupDescriptor descriptor3 = new GroupDescriptor(); descriptor3.GroupNames.Add("UnitsOnOrder", ListSortDirection.Ascending); descriptor3.GroupNames.Add("ReorderLevel", ListSortDirection.Descending); this.radGridView1.GroupDescriptors.Add(descriptor3); GroupDescriptor descriptor4 = new GroupDescriptor(); descriptor4.GroupNames.Add("Discontinued", ListSortDirection.Ascending); this.radGridView1.GroupDescriptors.Add(descriptor4); } private void radButton1_Click(object sender, EventArgs e) { GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1); SpreadExportRenderer exportRenderer = new SpreadExportRenderer(); string filePath = @"..\..\exported" + DateTime.Now.ToShortTimeString().Replace(":", "_") + ".xlsx"; spreadExporter.ExportGroupedColumns = true; spreadExporter.ExportChildRowsGrouped = true; spreadExporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport; spreadExporter.ExportVisualSettings = true; spreadExporter.SummariesExportOption = Telerik.WinControls.UI.Export.SummariesOption.ExportAll; spreadExporter.RunExport(filePath, exportRenderer); Process.Start(filePath); } Workaround: set the ExportChildRowsGrouped property to false.
To reproduce: 1. Add GridView which inherits the RadGridView 2. Populate the grid with some data 3. Add conditional formatting and set RowBackColor and CellBackColor 4. Subscribe to RowFormatting event and change the font of selected row: void radGridView2_RowFormatting(object sender, RowFormattingEventArgs e) { if (e.RowElement.IsSelected) { e.RowElement.Font = new Font(this.Font.FontFamily, this.Font.Size + 2, FontStyle.Bold); } else { e.RowElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local); //e.RowElement.Font = this.Font; } } 5. Select row with conditional formatting. The font of selected row is bold which is correct. Select another row and you will see that the previous row is still bold. Workaround: Subscribe to CellFormatting event instead RowFormatting void radGridView2_CellFormatting(object sender, CellFormattingEventArgs e) { if (e.Row.IsSelected) { e.CellElement.Font = new Font(this.Font.FontFamily, this.Font.Size + 2, FontStyle.Bold); } else { e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local); } }
BindingList<Item> items = new BindingList<Item>(); public Form1() { InitializeComponent(); for (int i = 0; i < 20; i++) { items.Add(new Item(i % 4, "Item" + i, "Type" + i % 2)); } this.radGridView1.DataSource = items; this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; } public class Item { public int Id { get; set; } public string Name { get; set; } public string Type { get; set; } public Item(int id, string name, string type) { this.Id = id; this.Name = name; this.Type = type; } } private void radButton1_Click(object sender, EventArgs e) { items.Insert(0, new Item(2, "Test", "Type0")); } WORKAROUND I: GridViewSynchronizationService.SuspendEvent(this.radGridView1.MasterTemplate, KnownEvents.CurrentChanged); Item item = new Item(2, "Test", "Type0"); items.Insert(0, item); GridViewSynchronizationService.ResumeEvent(this.radGridView1.MasterTemplate, KnownEvents.CurrentChanged); foreach (GridViewRowInfo row in this.radGridView1.Rows) { if (row.DataBoundItem == item) { this.radGridView1.CurrentRow = row; break; } } WORKAROUND II: this.radGridView1.Rows.CollectionChanged += Rows_CollectionChanged; this.radGridView1.GroupExpanding+=radGridView1_GroupExpanding; List<GridViewRowInfo> expandedGroups = new List<GridViewRowInfo>(); private void radGridView1_GroupExpanding(object sender, GroupExpandingEventArgs e) { if (!e.IsExpanded && shouldCollapse) { expandedGroups.Add(e.DataGroup.GroupRow); } } bool shouldCollapse = false; private void radButton1_Click(object sender, EventArgs e) { shouldCollapse = true; items.Insert(0, new Item(2, "Test", "Type0")); } private void Rows_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e) { if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add) { this.radGridView1.CurrentRow = e.NewItems[0] as GridViewRowInfo; this.radGridView1.CurrentRow.IsSelected = true; GridViewRowInfo parent = this.radGridView1.CurrentRow.Parent as GridViewRowInfo; if (parent != null) { parent.IsExpanded = true; } if (shouldCollapse) { shouldCollapse = false; foreach (GridViewRowInfo r in expandedGroups) { if (!ContainsParentRow(parent, r)) { r.IsExpanded = false; } } expandedGroups.Clear(); } } } private bool ContainsParentRow(GridViewRowInfo parent, GridViewRowInfo r) { GridViewGroupRowInfo group = r as GridViewGroupRowInfo; if (group != null) { foreach (GridViewRowInfo childRow in group.ChildRows) { return ContainsParentRow(parent, childRow); } } return parent == r.Parent; }
To reproduce: public RadForm1() { InitializeComponent(); radGridView1.AutoGenerateColumns = false; GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn(); decimalColumn.DataType = typeof(int); decimalColumn.Name = "DecimalColumn"; decimalColumn.HeaderText = "DecimalColumn"; decimalColumn.FieldName = "Dosage"; decimalColumn.Width = 200; radGridView1.MasterTemplate.Columns.Add(decimalColumn); radGridView1.DataSource = GetTable(); radGridView1.CellValidating += radGridView1_CellValidating; } void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { int value = Convert.ToInt32(e.Value); } Workaround: void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { int value = Convert.ToInt32(e.Value); }