To reproduce, use this code: AddGrid(); List<DropDownObject> lstDrp = new List<DropDownObject>(); DropDownObject drpObj = new DropDownObject(); drpObj.DropdownValue = "100"; drpObj.DropdownValueID = 1; DropDownObject drpObj2 = new DropDownObject(); drpObj2.DropdownValue = "100"; drpObj2.DropdownValueID = 2; DropDownObject drpObj1 = new DropDownObject(); drpObj1.DropdownValue = "101"; drpObj1.DropdownValueID = 1; lstDrp.Add(drpObj); lstDrp.Add(drpObj2); lstDrp.Add(drpObj1); DataTable dtMain = new DataTable(); DataColumn dcDropCol = new DataColumn(); dcDropCol.ColumnName = "DropDown Col"; dcDropCol.DataType = typeof(System.Int32); dtMain.Columns.Add(dcDropCol); DataRow dr = dtMain.NewRow(); dr["DropDown Col"] = 100; dtMain.Rows.Add(dr); var uniqueDropdownValues = lstDrp.GroupBy(s => s.DropdownValue).Select(s => s.First()); GridViewComboBoxColumn drpCol = new GridViewComboBoxColumn(); radGridView1.Columns.Add(drpCol); //first add the column //drpCol.DataType = typeof(int); //then change its data type to change the filtering type from string to int drpCol.Name = "DropDown Col"; drpCol.HeaderText = "Dropdown Col"; drpCol.FieldName = "Dropdown Col"; drpCol.DataSource = uniqueDropdownValues; drpCol.ValueMember = "DropdownValue"; drpCol.DisplayMember = "DropdownValue"; drpCol.Width = 200; drpCol.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown; drpCol.AutoCompleteMode = AutoCompleteMode.SuggestAppend; drpCol.AllowFiltering = true; radGridView1.EnableFiltering = true; radGridView1.ShowHeaderCellButtons = true; radGridView1.DataSource = dtMain; radGridView1.AllowAddNewRow = true;
It takes more than a minute to export 15000 cells. To reproduce: public Form1() { InitializeComponent(); //populate with data DataTable dt = new DataTable(); for (int i = 0; i < 50; i++) { dt.Columns.Add("Col" + i, typeof(string)); } DataColumn col; for (int i = 0; i < 3000; i++) { DataRow newRow = dt.Rows.Add(); for (int j = 0; j < dt.Columns.Count; j++) { col = dt.Columns[j]; newRow[col.ColumnName] = "Data." + i + " " + dt.Columns.IndexOf(col); } } this.radGridView1.DataSource = dt; this.radGridView1.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.AllCells); } private void radButton1_Click(object sender, EventArgs e) { Telerik.WinControls.UI.Export.SpreadExport.SpreadExport spreadExporter; spreadExporter = new SpreadExport(this.radGridView1,SpreadExportFormat.Xlsx ); spreadExporter.ExportVisualSettings = false; SaveFileDialog dialog = new SaveFileDialog(); dialog.FilterIndex = 1; dialog.DefaultExt = "*.xlsx"; dialog.Filter = "Excel file |*.xlsx"; if (dialog.ShowDialog() == DialogResult.OK) { Stopwatch sw = new Stopwatch(); sw.Start(); string fileName = dialog.FileName; spreadExporter.RunExport(fileName); sw.Stop(); Console.WriteLine(string.Format("Elapsed {0}", sw.Elapsed)); Process.Start(fileName); } }
If a RadGridView instance is not disposed explicitly and it is left for the finalizer to dispose, a null reference exception will be thrown. This can happen if the grid is not in the control tree of a form. The exception is caused by the fact that the SelfReferenceDataProvider is disposed twice in this case.
To reproduce: public Form1() { InitializeComponent(); ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition(); view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact")); view.ColumnGroups.Add(new GridViewColumnGroup("Details")); view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address")); view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact")); view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["CompanyName"]); view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactName"]); view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactTitle"]); view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Address"]); view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["City"]); view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Country"]); view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Phone"]); view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Fax"]); radGridView1.ViewDefinition = view; radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes; view.ColumnGroups[0].PinPosition = PinnedColumnPosition.Left; } Please see the attached screenshot. Workaround: add the columns belonging to the pinned group in a reversed order.
To reproduce: private void Form1_Load(object sender, EventArgs e) { this.productsTableAdapter.Fill(this.nwindDataSet.Products); this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories); radGridView1.DataSource = nwindDataSet.Categories; radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; GridViewTemplate template = new GridViewTemplate(); template.DataSource = nwindDataSet.Products; template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.MasterTemplate.Templates.Add(template); GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate); relation.ChildTemplate = template; relation.RelationName = "CategoriesProducts"; relation.ParentColumnNames.Add("CategoryID"); relation.ChildColumnNames.Add("CategoryID"); radGridView1.Relations.Add(relation); this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1]; } Workaround: this.radGridView1.MasterTemplate.ExpandAll(); this.radGridView1.MasterTemplate.CollapseAll(); this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1]; Another scenario: if you try to add a new row to the child template on the RadButton.Click event and call the EnsureVisible(true) method, it will not affect the grid, until you expand/collapse the parent row: private void radButton1_Click(object sender, EventArgs e) { //add the new row to the child template DataRow newRow = this.nwindDataSet.Products.Rows.Add(); newRow["CategoryID"] = 3; newRow["ProductName"] = "NewProduct"; this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1]; this.radGridView1.CurrentRow.EnsureVisible(true); } Workaround: private void radButton1_Click(object sender, EventArgs e) { //keep expanded rows List<GridViewRowInfo> expandedRows = new List<GridViewRowInfo>(); foreach (GridViewRowInfo row in this.radGridView1.Rows) { if (row.IsExpanded) { expandedRows.Add(row); } } //add the new row to the child template DataRow newRow = this.nwindDataSet.Products.Rows.Add(); newRow["CategoryID"] = 3; newRow["ProductName"] = "NewProduct"; //refresh the rows this.radGridView1.MasterTemplate.ExpandAll(); this.radGridView1.MasterTemplate.CollapseAll(); foreach (GridViewRowInfo rowToExpand in expandedRows) { rowToExpand.IsExpanded = true; } this.radGridView1.CurrentRow = null; this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1]; this.radGridView1.CurrentRow.EnsureVisible(true); }
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
Workaround: RadImageShape hint; protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitializeComponent(); hint = radGridView1.TableElement.RowDragHint; new Windows7Theme(); radGridView1.ThemeName = "Windows7"; radGridView1.TableElement.RowDragHint = hint; }
To reproduce: 1. Add text box and check box column to the grid. Add a filter descriptor to the text box column 2. Bind it to a DataTable with some data 3. Clear the columns 4. Add the columns once again => the exception will be thrown Workaround. 1. Create the following cell element: class MyHeaderCell : GridCheckBoxHeaderCellElement { public MyHeaderCell(GridViewColumn column, GridRowElement row) : base(column, row) { } protected override bool SetCheckBoxState() { if (this.ColumnIndex == -1) { return false; } return base.SetCheckBoxState(); } } 2. Subscribe to the grid's CreateCell event 3. Put the modified cell in action: void radGridView_CreateCell(object sender, GridViewCreateCellEventArgs e) { if (e.CellType == typeof(GridCheckBoxHeaderCellElement)) { e.CellType = typeof(MyHeaderCell); } }
To reproduce: - Add GridViewCheckBoxColumn and set the EnableHeaderCheckBox property to true. - Mark all check boxes and change the data source of the grid (use one where not all values are set to true). Workaround: Add new column when the data source is changed.
To reproduce: 1.Add a RadGridView with one column. 2.Select the form and in the Properties window, set the form's Localizable property to true. 3.Specify the column's HeaderText for the default language. 4.Set the form's Language property to French (France). 5.Specify the column's HeaderText for French (France). 6.Set the CurrentUICulture before the InitializeComponent method to "fr-FR". If you run the application, the column is localized as expected. 7.If you get back to the designer and change the form's Language property back to Default you will notice that the column's HeaderText disappears. Workaround: set the HeaderText programmatically according to the current language.
Currently if a user hits the decimal separator key the grid opens a cell for edit and selects its content. If the user does not notice this he may enter 1 instead of 0.1
To reproduce: - Add combobox column and filter the grid so just one row is visible. - In CellValueChanged event show a message box. - Change the value in the combo box column and click in the white space of the grid. Workaround: public class MyGridComboBoxCellElement : GridComboBoxCellElement { public MyGridComboBoxCellElement(GridViewColumn column, GridRowElement row) : base(column, row) { } public override void SetContent() { if (this.ColumnInfo != null) { base.SetContent(); } } protected override Type ThemeEffectiveType { get { return typeof(GridComboBoxCellElement); } } } void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) { if (e.CellType == typeof(GridComboBoxCellElement)) { e.CellElement = new MyGridComboBoxCellElement(e.Column, e.Row); } }
Synchronization between the filter descriptors collection and the excel like filtering.
To reproduce: private void Form1_Load(object sender, EventArgs e) { this.customersTableAdapter.Fill(this.nwindDataSet.Customers); GridViewMultiComboBoxColumn col = new GridViewMultiComboBoxColumn("MCCB column"); col.DataSource = this.customersBindingSource; col.DisplayMember = "ContactName"; col.ValueMember = "CustomerID"; this.radGridView1.Columns.Add(col); this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; } private void radGridView1_UserAddingRow(object sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e) { if (e.Rows.First().Cells[0].Value+"" =="ALFKI") { MessageBox.Show("Please select a product", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; this.radGridView1.BeginEdit(); } } Please refer to the attached gif file. Workaround: use the NumericUpDown.MouseDown event and call the RadGridView.BeginEdit method instead of activating the editor in the UserAddingRow event.
To reproduce: - Bind the grid to a self reference data, it should contain nullable bool value as well. - Add checkbox column: GridViewCheckBoxColumn chkBoxColumn = new GridViewCheckBoxColumn(); chkBoxColumn.EnableHeaderCheckBox = true; chkBoxColumn.ThreeState = true; chkBoxColumn.EditMode = EditMode.OnValueChange; - Start and uncheck and check one of the cells (in a data row) Workaround: public class MyGridCheckBoxHeaderCellElement : GridCheckBoxHeaderCellElement { public MyGridCheckBoxHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column,row) { } protected override bool SetCheckBoxState() { bool hasNullValue = false; foreach (GridViewRowInfo row in this.ViewInfo.Rows) { object cellValue = row.Cells[this.ColumnIndex].Value; if (cellValue == null) { hasNullValue = true; } } if (!hasNullValue) { return base.SetCheckBoxState(); } SetCheckBoxState(ToggleState.Indeterminate); return false; } }
To reproduce: 1. Set the RadGridView.MultiSelect property to true. 2. Set the SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect 3. When you select multiple cells, the SelectedCells collection stores the cells in reversed order instead of keeping the selection order. Compared to GridViewSelectionMode.FullRowSelect, this behavior is different. Workaround: iterate the SelectedCells collection in reversed order
To reproduce: use the following code snippet and perform the steps illustrated on the attached gif file. radGridView1.Columns.Add(new GridViewTextBoxColumn("A", "A")); radGridView1.Columns.Add(new GridViewTextBoxColumn("B", "B")); radGridView1.Columns.Add(new GridViewTextBoxColumn("C", "C")); radGridView1.Columns.Add(new GridViewTextBoxColumn("D", "D")); radGridView1.Columns.Add(new GridViewTextBoxColumn("E", "E")); radGridView1.Columns.Add(new GridViewTextBoxColumn("F", "F")); radGridView1.Columns[0].Width = 150; radGridView1.Columns[1].Width = 150; radGridView1.Columns[2].Width = 150; radGridView1.Columns[3].Width = 150; radGridView1.Columns[4].Width = 150; radGridView1.Columns[5].Width = 150; radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); radGridView1.Rows.Add("A", "B", "C", "D", "E", "F"); Workaround: private void radGridView1_Resize(object sender, EventArgs e) { if (this.radGridView1.IsInEditMode) { this.radGridView1.EndEdit(); this.radGridView1.BeginEdit(); } } public class CustomGrid : RadGridView { public override string ThemeClassName { get { return typeof(RadGridView).FullName; } } protected override RadGridViewElement CreateGridViewElement() { return new CustomRadGridViewElement(); } } public class CustomRadGridViewElement : RadGridViewElement { protected override Type ThemeEffectiveType { get { return typeof(RadGridViewElement); } } protected override GridViewEditManager CreateEditorManager() { return new CustomGridViewEditManager(this); } } public class CustomGridViewEditManager : GridViewEditManager { public CustomGridViewEditManager(RadGridViewElement gridViewElement) : base(gridViewElement) { } protected override void InitializeEditor(IInputEditor activeEditor) { if (activeEditor == null) { activeEditor = this.GridViewElement.CurrentColumn.GetDefaultEditor(); this.ActiveEditor = activeEditor; } base.InitializeEditor(activeEditor); } }
To reproduce: Open Demo application >> GridView >> Export >> Export Hierarchy