Add an ExportToXlsx option into the native RadGridView exporting. It has been done for WPF (http://docs.telerik.com/devtools/wpf/controls/radgridview/export/export-xlsx) - why not WinForms. This would avoid the pain of having to implement the export using RadSpreadProcessing.
Please refer to the attached project. Workakround: call the BeginEdit method in the RadGridView.Click event.
To reproduce: public class Item { public int Id { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public Item(int id, string name, DateTime date) { this.Id = id; this.Name = name; this.Date = date; } } public Form1() { InitializeComponent(); List<Item> items = new List<Item>(); for (int i = 0; i < 10; i++) { items.Add(new Item(i,"Item" + i,DateTime.Now.AddHours(i))); } this.radGridView1.DataSource = items; this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; } private void Form1_Load(object sender, EventArgs e) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB"); this.radGridView1.Columns["Date"].ExcelExportFormatString = "M/d/yyyy h:mm tt"; this.radGridView1.Columns["Date"].ExcelExportType = DisplayFormatType.Custom; GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1); spreadExporter.ExportVisualSettings = true; SpreadExportRenderer exportRenderer = new SpreadExportRenderer(); string fileName = @"..\..\exportedFile" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx"; spreadExporter.RunExport(fileName, exportRenderer); Process.Start(fileName); }
To reproduce: GridViewImageColumn imageColumn = new GridViewImageColumn(); imageColumn.Name = "ImageColumn"; imageColumn.FieldName = "ImageColumn"; imageColumn.HeaderText = "Picture"; radGridView1.MasterTemplate.Columns.Add(imageColumn); List<classBinding> databinding = new List<classBinding>(); for (int i = 0; i < 35000; i++) { databinding.Add(new classBinding() { ImageColumn = Properties.Resources.Alarm2, }); } radGridView1.DataSource = databinding; public class classBinding { public System.Drawing.Bitmap ImageColumn { get; set; } }
For now you can manually add the columns to the ExcelFilteredColumns collection when the filters are added in code: FilterDescriptor fd = new FilterDescriptor("Value", Telerik.WinControls.Data.FilterOperator.IsEqualTo, "B"); fd.IsFilterEditor = true; radGridView1.FilterDescriptors.Add(fd); this.radGridView1.MasterTemplate.ExcelFilteredColumns.Add( this.radGridView1.Columns[0] );
"High Performance with RadGridView and Virtual Mode including Filtering, Sorting and Grouping" example is not working for RadGridView Q3 2015. When I click on the Column header for sorting ( same thing for grouping and filtering) and I m getting exception "Sorting operation is not supported in VirtualMode.". Same sample is working for Q3 2014. Following is the URL for the sample http://www.telerik.com/support/kb/winforms/gridview/details/high-performance-with-radgridview-and-virtual-mode-including-filtering-sorting-and-grouping
To reproduce: public Form1() { InitializeComponent(); this.radGridView1.Columns.Add("Col1"); this.radGridView1.Rows.Add("word \u00AD word"); this.radGridView1.Rows.Add("word - word"); } Workaround: replace "\u00AD" with "-" private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) { e.CellElement.Text = e.CellElement.Text.Replace("\u00AD", "-"); }
To reproduce: use the following code snippet and click the button twice. private DataTable GetTable01() { DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(string)); table.Columns.Add("Date", typeof(DateTime)); // Here we add five DataRows. table.Rows.Add(25, "Indocin", "David", DateTime.Now); table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); return table; } private void button1_Click_1(object sender, EventArgs e) { DataTable table01 = GetTable01(); radGridView1.Rows.Clear(); radGridView1.DataSource = table01; } WORKAROUND I: this.radGridView1.DataError += radGridView1_DataError; private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e) { if (e.Exception is ArgumentException && e.Exception.Message == "Cannot clear this list.") { this.radGridView1.BeginUpdate(); while (this.radGridView1.Rows.Count > 0) { this.radGridView1.Rows.RemoveAt(0); } this.radGridView1.EndUpdate(); } } WORKAROUND II: while (this.radGridView1.Rows.Count > 0) { this.radGridView1.Rows.RemoveAt(this.radGridView1.Rows.Count - 1); }
To reproduce: public Form1() { InitializeComponent(); this.radGridView1.CellFormatting+=radGridView1_CellFormatting; DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Name",typeof(string)); for (int i = 0; i < 100; i++) { dt.Rows.Add(i,"Item"+i); } this.radGridView1.DataSource = dt; this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; } private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) { e.Row.Height = 40; } private void radButton1_Click(object sender, EventArgs e) { this.radGridView1.TableElement.ScrollToRow(this.radGridView1.Rows.Count - 1); } Workaround: instead of using the CellFormatting event to set the Row.Height, you can set the TableElement.RowHeight property.
To reproduce: 1. Add a grid to a form. 2. Set its SplitMode to vertical or horizontal. 3. Set its SynchronizeCurrentRowInSplitMode to false. You will notice that both grids are synchronized. Workaround: Add two RadgridViews in a RadSplitContainer with two split panels and use two separate data sources. For example: List<string> ds = new List<string>(); grid1.DataSource = ds; grid2.DataSource = ds.ToArray();
Steps to reproduce: 1. Add a GridViewDateTimeColumn to a grid. 2. Add rows where one or more rows should contain null as the columns value. 3. Sort the grid by the date time column. WORKAROUND: Create a custom RadGridDateTimeConverter and assign it as the column's date type converter: public class CustomRadGridDateTimeConverter : RadGridDateTimeConverter { public CustomRadGridDateTimeConverter(GridViewDateTimeColumn column) : base(column) { } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(DateTime) && value == null) { return DateTime.MinValue; } return base.ConvertTo(context, culture, value, destinationType); } } this.radGridView1.Columns["DateTime"].DataTypeConverter = new CustomRadGridDateTimeConverter(this.radGridView1.Columns["DateTime"] as GridViewDateTimeColumn);
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.
There should be a Enum (Left, Right, None) property of the Expander Column indicating whether the position of the expander column should be left right or none. This would be especially important during pinning activities meaning no matter how many columns are being pinned and repositioned in the pinned area of the grid, it would always remain on the left, right or none.
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; }
The conditional formatting collection get deleted after closing the property builder. To reproduce : Add a gridview with a datasource. Open property builder Select a column Advance -> ConditionalFormattingObjectList Add a expression, set a name Press Ok If you click the ConditionalFormattingObjectList, you can see the expression If you click close the Property Builder, the list is not saved when you open it again.
When you use a custom GroupComparer for the MasterTemplate, grouping is performed successfully for the first time. However, if you remove all groups and perform grouping again for the same columns, the grid behavior is not as expected: you will notice groups mismatching or duplication. Here is a sample code snippet which incorrect behavior is illustrated on the attached gif file: public Form1() { InitializeComponent(); DataTable dt = new DataTable(); dt.Columns.Add("Reference"); dt.Columns.Add("Test Case"); dt.Columns.Add("ChBW"); dt.Columns.Add("Voltage"); dt.Columns.Add("Environmental Conditions"); dt.Columns.Add("RadioAccessTechnology"); dt.Rows.Add("4.2.1", "E-Utran FDD...", "10", "C Nominal-2", "T Nominal - V Nominal", "E-UTRAN Only"); dt.Rows.Add("5.2.1", "E-Utran FDD...", "3", "C Nominal-1", "T Nominal - V Nominal", "E-UTRAN Only"); dt.Rows.Add("14.2.1", "E-Utran FDD...", "1", "C Nominal-3", "T Nominal - V Nominal", "E-UTRAN Only"); dt.Rows.Add("2.2.1", "E-Utran FDD...", "4", "C Nominal-2", "T Nominal - V Nominal", "E-UTRAN Only"); dt.Rows.Add("7.2.1", "E-Utran FDD...", "12", "C Nominal-1", "T Nominal - V Nominal", "E-UTRAN Only"); dt.Rows.Add("2.2.1", "E-Utran FDD...", "2", "C Nominal-3", "T Nominal - V Nominal", "E-UTRAN Only"); this.radGridControlSelection.DataSource = dt; this.radGridControlSelection.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; this.radGridControlSelection.MasterTemplate.GroupComparer = new GroupComparer(); } public class GroupComparer : IComparer<Group<GridViewRowInfo>> { public int Compare(Group<GridViewRowInfo> x, Group<GridViewRowInfo> y) { if (x.Level != y.Level) { } DataGroup group = x as DataGroup; var a = x.Header; var b = y.Header; int valueA; int valueB; if (group == null) { group = y as DataGroup; } if (group != null && group.GroupDescriptor != null && group.GroupDescriptor.GroupNames.Count > 0) { string propertyName = group.GroupDescriptor.GroupNames.First().PropertyName; if ((propertyName.ToUpper() == "VOLTAGE")) { int indexA = GetIndexContain(a.ToString().Split(new char[] { '-' })[1]); int indexB = GetIndexContain(b.ToString().Split(new char[] { '-' })[1]); if (indexA == indexB) { return 0; } else if (indexA < indexB) { return -1; } else { return 1; } } else if (propertyName.ToUpper() == "RADIOACCESSTECHNOLOGY") { return x.Key.ToString().CompareTo(y.Key.ToString()); } // BAND else if (propertyName.ToUpper() == "CHBW") { Int32.TryParse(a, out valueA); Int32.TryParse(b, out valueB); //ASCENDING SELECTED if (group.GroupDescriptor.GroupNames.First().Direction == ListSortDirection.Ascending) { if (valueA > valueB) { return 1; } else if (valueA < valueB) { return -1; } else { return 0; } } //DESCENDING else { if (valueA > valueB) { return -1; } else if (valueA < valueB) { return 1; } else { return 0; } } } } return x.Key.ToString().CompareTo(y.Key.ToString()); } private int GetIndexContain(string a) { int parsedValue; if (int.TryParse(a, out parsedValue)) { return 10 - parsedValue; } return -1; } } Workaround: public class Grid:RadGridView { public override string ThemeClassName { get { return typeof(RadGridView).FullName; } } protected override RadGridViewElement CreateGridViewElement() { return new CustomGridViewElement(); } } public class CustomGridViewElement : RadGridViewElement { protected override Type ThemeEffectiveType { get { return typeof(RadGridViewElement); } } protected override MasterGridViewTemplate CreateTemplate() { return new CustomMasterGridViewTemplate(); } } public class CustomMasterGridViewTemplate : MasterGridViewTemplate { protected override GridViewListSource CreateListSource() { return new CustomGridViewListSource(this); } } public class CustomGridViewListSource : GridViewListSource { public CustomGridViewListSource(GridViewTemplate template) : base(template) { } protected override RadCollectionView<GridViewRowInfo> CreateDefaultCollectionView() { return new CustomGridDataView(this); } } public class CustomGridDataView : GridDataView { public CustomGridDataView(GridViewListSource listSource) : base(listSource) { } protected override GroupBuilder<GridViewRowInfo> CreateGroupBuilder() { return new CustomGroupBuilder(this.Indexer); } } public class CustomGroupBuilder : GridGroupBuilder { public CustomGroupBuilder(Index<GridViewRowInfo> index) : base(index) { } protected override Group<GridViewRowInfo> GetGroup(GroupCollection<GridViewRowInfo> cache, Group<GridViewRowInfo> newGroup, Group<GridViewRowInfo> parent, object key, int level) { GroupDescriptor currentDescriptor = this.CollectionView.GroupDescriptors[level]; DataGroup group = (DataGroup)base.GetGroup(null, newGroup, parent, key, level); if (group.GroupDescriptor != null && group.GroupDescriptor != currentDescriptor) { SetGroupDescriptor(group, null); IGroupFactory<GridViewRowInfo> groupFactory = this.CollectionView.GroupFactory; group = (DataGroup)groupFactory.CreateGroup(key, parent); group.GroupBuilder = this; } SetGroupDescriptor(group, currentDescriptor); return group; } private void SetGroupDescriptor(DataGroup dataGroup, GroupDescriptor currentDescriptor) { FieldInfo fi = typeof(DataGroup).GetField("groupDescriptor", BindingFlags.NonPublic | BindingFlags.Instance); fi.SetValue(dataGroup, currentDescriptor); } }
To reproduce: use the following code snippet: Sub New() InitializeComponent() Me.RadGridView1.EnableFiltering = True Me.RadGridView1.ShowHeaderCellButtons = True Dim dt As New DataTable dt.Columns.Add("Id", GetType(Integer)) dt.Columns.Add("Name", GetType(String)) dt.Columns.Add("Type", GetType(String)) dt.Columns.Add("Active", GetType(Boolean)) Dim typeList As New List(Of String) typeList.Add("REFERRAL") typeList.Add("EMPLOYEE") typeList.Add("Type3") typeList.Add("Type4") Dim rand As New Random For index = 1 To 10 dt.Rows.Add(index, "Name" & index, typeList(rand.Next(0, typeList.Count)),If(index mod 2=0, True,false)) Next Me.RadGridView1.AutoGenerateColumns = False Dim decimalColumn As New GridViewDecimalColumn("ID") decimalColumn.FieldName = "Id" RadGridView1.MasterTemplate.Columns.Add(decimalColumn) Dim textBoxColumn As New GridViewTextBoxColumn("Name") textBoxColumn.FieldName = "Name" RadGridView1.MasterTemplate.Columns.Add(textBoxColumn) Dim supplierColumn As GridViewComboBoxColumn = New GridViewComboBoxColumn("Type") supplierColumn.FieldName = "Type" supplierColumn.DataSource = typeList Me.RadGridView1.Columns.Add(supplierColumn) Dim checkBoxColumn As New GridViewCheckBoxColumn("Active") checkBoxColumn.FieldName = "Active" RadGridView1.MasterTemplate.Columns.Add(checkBoxColumn) Me.RadGridView1.DataSource = dt Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill End Sub Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click Dim activeFilter As New FilterDescriptor() activeFilter.PropertyName = "Active" activeFilter.Operator = FilterOperator.IsEqualTo activeFilter.Value = True Dim typeFilter As New CompositeFilterDescriptor() typeFilter.FilterDescriptors.Add(New FilterDescriptor("Type", FilterOperator.IsEqualTo, "EMPLOYEE")) typeFilter.FilterDescriptors.Add(New FilterDescriptor("Type", FilterOperator.IsEqualTo, "REFERRAL")) typeFilter.LogicalOperator = FilterLogicalOperator.Or Dim overallFilterDescriptor As New CompositeFilterDescriptor() 'overallFilterDescriptor.PropertyName = "Type" 'overallFilterDescriptor.IsFilterEditor = True overallFilterDescriptor.FilterDescriptors.Add(typeFilter) overallFilterDescriptor.FilterDescriptors.Add(activeFilter) overallFilterDescriptor.LogicalOperator = FilterLogicalOperator.And Me.RadGridView1.FilterDescriptors.Add(overallFilterDescriptor) End Sub Run the project and click the button. You will see that the filter button is not orange indicating that there is applied filter. Additionally, the "Clear filter" option is disabled and the user is not allowed to see the entire data any more. Workaround: set the overall CompositeFilterDescriptor.PropertyName to a specific column and the IsFilterEditor property to true. Thus, you will be allowed to clear the filter from this column.
i would like to customize the grid like below attached screen shot,is it possible using telerik win forms (rad grid view), if possible can you please send me sample code for that, if not possible can you suggest me alternate solution for this requirement.
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