http://www.telerik.com/forums/gridview---adding-a-third-hierarchy-or-level#HdPZFtCJR0q1OCXxVR5wjg Dim ID As New GridViewDecimalColumn() ID.Name = "ID" ID.HeaderText = "Id" RadGridView1.MasterTemplate.Columns.Add(ID) Dim Name As New GridViewTextBoxColumn() Name.Name = "Name" Name.HeaderText = "Name" Name.Width = 100 RadGridView1.MasterTemplate.Columns.Add(Name) Dim Under_Appeal As New GridViewCheckBoxColumn() Under_Appeal.DataType = GetType(Boolean) Under_Appeal.Name = "Under_Appeal" Under_Appeal.HeaderText = "Under Appeal" RadGridView1.MasterTemplate.Columns.Add(Under_Appeal) Dim Terminated As New GridViewCheckBoxColumn() Terminated.DataType = GetType(Boolean) Terminated.Name = "Terminated" Terminated.HeaderText = "Terminated" RadGridView1.MasterTemplate.Columns.Add(Terminated) Dim Hash As New GridViewDecimalColumn() Hash.Name = "Hash" Hash.HeaderText = "#" RadGridView1.MasterTemplate.Columns.Add(Hash) RadGridView1.Rows.Add(1, "John", True, True) RadGridView1.Rows.Add(2, "Mary", True, False) RadGridView1.Rows.Add(3, "Peter", False, True) Dim template As New GridViewTemplate template.Columns.Add(New GridViewDecimalColumn("ParentID")) template.Columns.Add(New GridViewTextBoxColumn("TEXT")) template.Columns.Add(New GridViewDecimalColumn("PRICE")) RadGridView1.MasterTemplate.Templates.Add(template) Dim relation As New GridViewRelation(RadGridView1.MasterTemplate) relation.ChildTemplate = template relation.RelationName = "PersonProduct" relation.ParentColumnNames.Add("ID") relation.ChildColumnNames.Add("ParentID") RadGridView1.Relations.Add(relation) template.Rows.Add(1, "sugar", 2.0) template.Rows.Add(1, "cake", 12.0) template.Rows.Add(1, "butter", 3.0) template.Rows.Add(2, "cake", 12.0) Dim template2 As New GridViewTemplate template2.Columns.Add(New GridViewDecimalColumn("ParentID2")) template2.Columns.Add(New GridViewTextBoxColumn("TYPE")) template2.Columns.Add(New GridViewDecimalColumn("QTY")) RadGridView1.MasterTemplate.Templates(0).Templates.Add(template2) Dim relation2 As New GridViewRelation(RadGridView1.MasterTemplate.Templates(0)) relation2.ChildTemplate = template2 relation2.RelationName = "PersonProduct2" relation2.ParentColumnNames.Add("ParentID") relation2.ChildColumnNames.Add("ParentID2") RadGridView1.Relations.Add(relation2) template2.Rows.Add(1, "brown", 1) template2.Rows.Add(1, "whiter", 3) template2.Rows.Add(2, "banana", 2) I am getting errors at runtime when I try to see the 3rd level in the hyerarchy.
FIX. RadGridView - seting the HeaderImage of a column in the PropertyBuilder results in Object Reference message
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;
Save and load layout to work in all view definitions.
ADD. RadGridView should support filtering operations when custom TypeConverters are used.
To reproduce: this.radGridView1.DataSource = this.ordersBindingSource; GridViewDateTimeColumn col = this.radGridView1.Columns["OrderDate"] as GridViewDateTimeColumn; col.ExcelExportType = DisplayFormatType.GeneralDate; col.ExcelExportFormatString = "dd-MMM-yy"; private void radButton1_Click(object sender, EventArgs e) { SpreadExport spreadExporter = new SpreadExport(radGridView1); spreadExporter.RunExport(@"..\..\..\exportedFileQ12015.xlsx"); Process.Start(@"..\..\..\exportedFileQ12015.xlsx"); } Workaround: private void radButton1_Click(object sender, EventArgs e) { SpreadExport spreadExporter = new SpreadExport(radGridView1); spreadExporter.CellFormatting += spreadExporter_CellFormatting; spreadExporter.RunExport(@"..\..\..\exportedFileQ12015.xlsx"); Process.Start(@"..\..\..\exportedFileQ12015.xlsx"); } private void spreadExporter_CellFormatting(object sender, Telerik.WinControls.UI.Export.SpreadExport.CellFormattingEventArgs e) { if (e.GridColumnIndex == 3 && e.GridCellInfo.Value is DateTime) { CellValueFormat cvf = new CellValueFormat("dd-MMM-yy"); e.CellSelection.SetFormat(cvf); } }
To reproduce : - Set conditional formatting for all grid cells. - Iterate all grid cells and set their value. Workaround: Use Begin/End update block.
Workaround: use the API of RadGridView to delete the row
Currently none of the exporters can be canceled.
Presently it is not possible to persist customer created formatting objects in RadGridView.
Workaround: to avoid this behavior iterate the Rows collection of the master template and invoke their HasChildRows() method. which will sync up their parent
RadGridView should be able to create new rows using objects with properties matching the FieldNames of the control's columns.
To reproduce: BindingList<Item> items = new BindingList<Item>(); public Form1() { InitializeComponent(); Item dataItem1 = new Item(1); dataItem1.Name = "Cat"; dataItem1.GroupName = "Animal"; dataItem1.GroupSortPriority = 2; items.Add(dataItem1); Item dataItem2 = new Item(2); dataItem2.Name = "Kitten"; dataItem2.GroupName = "Animal"; dataItem2.GroupSortPriority = 2; dataItem2.ParentIndex = 1; items.Add(dataItem2); Item dataItem3 = new Item(3); dataItem3.Name = "Trout"; dataItem3.GroupName = "Fish"; dataItem3.GroupSortPriority = 1; items.Add(dataItem3); radGridView1.Relations.AddSelfReference(radGridView1.MasterTemplate, "Index", "ParentIndex"); radGridView1.DataSource = items; } public class Item { public Item(int index) { Index = index; } public int Index { get; private set; } public int ParentIndex { get; set; } public string Name { get; set; } public string GroupName { get; set; } public int GroupSortPriority { get; set; } } public class GridGroupComparer : IComparer<Group<GridViewRowInfo>> { public GridGroupComparer() { } public int Compare( Group<GridViewRowInfo> x, Group<GridViewRowInfo> y) { if (null == x.Key || null == y.Key) return 1; GridViewRowInfo xGridViewRowInfo = x.DefaultIfEmpty(null).First(); GridViewRowInfo yGridViewRowInfo = y.DefaultIfEmpty(null).First(); if (null == xGridViewRowInfo || null == yGridViewRowInfo) return x.Key.GetHashCode().CompareTo(y.Key.GetHashCode()); Item xGridRowDataItem = xGridViewRowInfo.DataBoundItem as Item; Item yGridRowDataItem = yGridViewRowInfo.DataBoundItem as Item; if (null == xGridRowDataItem || null == yGridRowDataItem) return x.Key.GetHashCode().CompareTo(y.Key.GetHashCode()); if (xGridRowDataItem.GroupSortPriority > yGridRowDataItem.GroupSortPriority) return 1; if (xGridRowDataItem.GroupSortPriority < yGridRowDataItem.GroupSortPriority) return -1; return 0; } } private void Form1_Load(object sender, EventArgs e) { GridGroupComparer groupComparer = new GridGroupComparer(); radGridView1.MasterTemplate.GroupComparer = groupComparer; GroupDescriptor descriptor = new GroupDescriptor(); descriptor.GroupNames.Add("GroupName", ListSortDirection.Ascending); radGridView1.GroupDescriptors.Add(descriptor); } If you remove the Self-referencing hierarchy, you will notice that the GroupComparer is respected.
ADD. RadGridView - add the ability to group by a certain column and display the groups sorted by the values of another column
To reproduce: public Form1() { InitializeComponent(); GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn("DecimalColumn"); decimalColumn.FormatString = "{0:N0}"; decimalColumn.FieldName = "Price"; radGridView1.MasterTemplate.Columns.Add(decimalColumn); GridViewCommandColumn commandColumn = new GridViewCommandColumn("CommandColumn"); commandColumn.FormatString = "{0:N0}"; commandColumn.FieldName = "Price"; radGridView1.MasterTemplate.Columns.Add(commandColumn); radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; this.radGridView1.SaveLayout(@"..\..\..\layout.xml"); this.radGridView1.LoadLayout(@"..\..\..\layout.xml"); FillData(); } private void FillData() { List<Item> items = new List<Item>(); for (int i = 0; i < 5; i++) { items.Add(new Item(i * 2.35m)); } radGridView1.DataSource = items; } public class Item { public decimal Price { get; set; } public Item(decimal price) { this.Price = price; } } Workaround: use the CellFormatting event and format the GridCommandCellElement.CommandButton.Text property: private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) { if (e.Column is GridViewCommandColumn && e.CellElement.Value != null) { GridCommandCellElement commandCell = e.CellElement as GridCommandCellElement; commandCell.CommandButton.Text = string.Format("{0:N0}", e.CellElement.Value); } }
Just to let you know that if I load the layout into a gridview before the initial data load the formatting of some cells does not work. Please refer to the attached example. Simply changing the two lines of code will work around the issue. If the data is reloaded afterwards by means of the third button, the problem does not reoccur. So it's a matter of loading data before loading a layout for the first time. Workaround: set the DataSource after the layout is loaded
Steps to reproduce: 1. Add two classes to the project: public class ParentClass { public int MyProperty { get; set; } public List<ChildClass> Children { get; set; } } public class ChildClass { public int MyProperty { get; set; } public SomeEnum Enumera { get; set; } } public enum SomeEnum { first, second, third } 2. Add two RadGridViews to a form. 3. Add two binding sources one with DataSource the ParentClass, the second with DataSource the first binding source and DataMember "Children" 4. Bind the grids to the two data sources. 5. Edit some column properties of the grid bound to the second data source. 6. Build the project and try to open the smart tag of the grid. Some times you will see a message box with text "Object does not match target type."
Version 2014.3.1202.40 scrolling worsened How to reproduce: public partial class Form1 : Form { public Form1() { InitializeComponent(); DataTable dataTable = new DataTable(); dataTable.Columns.Add("Id", typeof(int)); dataTable.Columns.Add("Id2", typeof(int)); dataTable.Columns.Add("Id3", typeof(int)); dataTable.Columns.Add("Id4", typeof(int)); for (int i = 0; i < 10000; i++) { dataTable.Rows.Add(i, i + 10, i +20, i+30); } this.radGridView1.DataSource = dataTable; this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; this.Load += Form1_Load; } private void Form1_Load(object sender, EventArgs e) { ExpressionFormattingObject idObj = new ExpressionFormattingObject("1", "Id % 2 = 0", false); idObj.CellBackColor = Color.SkyBlue; idObj.CellForeColor = Color.Red; this.radGridView1.Columns["Id"].ConditionalFormattingObjectList.Add(idObj); ExpressionFormattingObject idObj2 = new ExpressionFormattingObject("1", "Id2 % 2 = 0", false); idObj2.CellBackColor = Color.LightGray; idObj2.CellForeColor = Color.Red; this.radGridView1.Columns["Id2"].ConditionalFormattingObjectList.Add(idObj2); ExpressionFormattingObject idObj3 = new ExpressionFormattingObject("1", "Id3 % 2 = 0", false); idObj3.CellBackColor = Color.LightGreen; idObj3.CellForeColor = Color.Red; this.radGridView1.Columns["Id3"].ConditionalFormattingObjectList.Add(idObj3); ExpressionFormattingObject idObj4 = new ExpressionFormattingObject("1", "Id4 % 2 = 0", false); idObj4.CellBackColor = Color.LightYellow; idObj4.CellForeColor = Color.Red; this.radGridView1.Columns["Id4"].ConditionalFormattingObjectList.Add(idObj4); } } Workaround: Apply formatting on CellFormatting event