If RadGridView is bound to custom objects that implement IComparable<T>, Excel-like filtering does not work. Currently, the issue can be avoided through implementing IComparable instead.
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.
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);
}
}
Deleting a Template in the Property Builder does work.
Workaround: set up the templates from code, http://www.telerik.com/help/winforms/gridview-overview.html
To reproduce:
public Form1()
{
InitializeComponent();
GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn("Select");
checkBoxColumn.EnableHeaderCheckBox = true;
radGridView1.MasterTemplate.Columns.Insert(0, checkBoxColumn);
for (int i = 0; i < 10; i++)
{
this.radGridView1.Rows.Add(false);
}
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.MultiSelect = true;
this.radGridView1.HeaderCellToggleStateChanged += radGridView1_HeaderCellToggleStateChanged;
}
private void radGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
{
if (e.State.ToString() == "On")
this.radGridView1.SelectAll();
else
this.radGridView1.ClearSelection();
}
Workaround 1:
private void radGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
{
bool selected = e.State.ToString() == "On";
foreach (GridViewRowInfo r in this.radGridView1.Rows)
{
r.IsSelected = selected;
}
}
Workaround 2:
private void radGridView1_MouseUp(object sender, MouseEventArgs e)
{
RadCheckBoxElement el = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as RadCheckBoxElement;
if (el!=null)
{
GridCheckBoxHeaderCellElement headerCell = el.Parent as GridCheckBoxHeaderCellElement;
bool selected = el.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On;
if (headerCell!=null)
{
if (selected)
{
this.radGridView1.SelectAll();
}
else
{
this.radGridView1.ClearSelection();
}
}
}
}
To reproduce:
-add a RadGridView and a RadButton;
Use the following code:
public Form1() { InitializeComponent(); List<Item> list = new List<Item>() { new Item(1, "<AUD#F-DC>") }; radGridView1.DataSource = list; } public class Item { public int ID { get; set; } public string Title { get; set; } public Item(int iD, string title) { this.ID = iD; this.Title = title; } } private void Form1_Load(object sender, EventArgs e) { this.employeesTableAdapter.Fill(this.nwindDataSet.Employees); } private void radButton1_Click(object sender, EventArgs e) { ExportToPDF pdfExporter = new ExportToPDF(this.radGridView1); pdfExporter.PdfExportSettings.Title = "My PDF Title"; pdfExporter.PdfExportSettings.PageWidth = 297; pdfExporter.PdfExportSettings.PageHeight = 210; pdfExporter.PageTitle = "temp"; pdfExporter.FitToPageWidth = true; pdfExporter.SummariesExportOption = SummariesOption.ExportAll; pdfExporter.ExportVisualSettings = true; try { pdfExporter.RunExport(@"..\..\..\pdfExport.pdf"); } catch (IOException ex) { RadMessageBox.Show(this, ex.Message, "I/O Error", MessageBoxButtons.OK, RadMessageIcon.Error); } }
Workaround:
pdfExporter.HTMLCellFormatting += pdfExporter_HTMLCellFormatting;
private void pdfExporter_HTMLCellFormatting(object sender, HTMLCellFormattingEventArgs e) { string val = e.HTMLCellElement.Value; e.HTMLCellElement.Value = val.Replace("<", "<").Replace(">", ">"); }
To reproduce:
public Form1()
{
InitializeComponent();
Random r = new Random();
DataTable table = new DataTable("table1");
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Bool", typeof(bool));
table.Columns.Add("DateColumn", typeof(DateTime));
for (int i = 0; i < 10; i++)
{
table.Rows.Add(i, "Row " + i, r.Next(10) > 5 ? true : false, DateTime.Now.AddHours(i));
}
DataSet dataSet = new DataSet();
dataSet.Tables.Add(table);
radGridView1.DataBindingComplete += radGridView1_DataBindingComplete;
this.radGridView1.DataSource = dataSet;
this.radGridView1.DataMember = "table1";
}
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
}
1. Create a new project with RadGridView.
2. Bind it and set grouping.
3. Add a summary row and set ShowParentGroupSummaries property to true.
4. Handle the ViewCellFormatting event and set all summary rows to be IsVisible = false when the processed cell is GridSummaryCellElement:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement is GridSummaryCellElement)
{
e.Row.IsVisible = false;
}
}
CORRECT WAY TO HANDLE THIS CASE:
Hide the summary rows in the groups you want after grouping/data binding.
To hide the first bottom summary row of the first group in a RadGridView use the following code:
this.radGridView1.Groups[0].GroupRow.BottomSummaryRows[0].IsVisible = false;
Workaround:
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.GridViewElement.EditorManager = new MyGridViewEditManager(this.radGridView1.GridViewElement);
}
}
public class MyGridViewEditManager : GridViewEditManager
{
public MyGridViewEditManager(RadGridViewElement gridViewElement)
: base(gridViewElement) { }
public override bool BeginEdit()
{
this.GridViewElement.CurrentView.EnsureCellVisible(this.GridViewElement.CurrentCell.RowInfo, this.GridViewElement.CurrentCell.ColumnInfo);
this.GridViewElement.CurrentCell.UpdateLayout();
return base.BeginEdit();
}
}
The performance of excel-like filtering when you have more than 5000+ row in RadGridView.
To reproduce:
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(int)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
for (int i = 0; i < 50; i++)
{
dt.Rows.Add(i, "Item" + i);
}
radGridView1.DataSource = dt;
radGridView1.MasterTemplate.MultiSelect = true;
}
1. Load a grid with enough rows to make scrolling necessary to see the bottom row.
2. Drag a column header into the group area.
3. Move the vertical scroll bar down. It doesn't matter if you scroll all the way to the end or just barely move the vertical scroll bar, as long as it isn't all the way to the top.
4. Put the mouse on the "X" of the group descriptor. Hold the left mouse button and move the mouse.
Workaround: use custom row behavior:
BaseGridBehavior gridBehavior = rgvTest.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridDataRowBehavior());
public class CustomGridDataRowBehavior : GridDataRowBehavior
{
public CustomGridDataRowBehavior()
{
typeof(GridRowBehavior).GetField("orderedRows", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance).SetValue(this, new List<GridViewRowInfo>()) ;
}
public override bool OnMouseUp(MouseEventArgs e)
{
bool result = base.OnMouseUp(e);
typeof(GridRowBehavior).GetField("orderedRows", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance).SetValue(this, new List<GridViewRowInfo>()) ;
return result;
}
}
Vertical scrolling of self-referencing hierarchy in RadGridView is slow when there is more than 10 columns.
RadGridView.- HierarchyDataProvider property of the GridViewTemplate should be set after the GridViewTemplate is added to Templates Collection.
To reproduce:
- Subscribe to the following RowsChanged event handler:
void radGridView1_RowsChanged(object sender, GridViewCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.ItemChanged)
{
GridViewDataRowInfo updrow = (GridViewDataRowInfo)e.NewItems[0];
GridViewDataRowInfo oldrow = (GridViewDataRowInfo)e.OldItems[0];
if (updrow.Cells[2].Value != oldrow.Cells[2].Value)
{
Console.WriteLine(updrow.Cells[2].Value);
Console.WriteLine(oldrow.Cells[2].Value);
}
}
}
- You will notice that both values are always equal.
Workaround:
The CellValidating event can be used instead.
To reproduce:
Set RadGridView MultiSelect property to true and select several rows. Export RadGridView using GridViewSpreadExport and only current row will be preserved(all selected rows are lost).
Workaround:
Save all selected rows in a collection before the export and after it set saved rows as selected.
List<GridViewRowInfo> selectedRows = new List<GridViewRowInfo>();
foreach (GridViewRowInfo row in this.radGridView1.SelectedRows)
{
selectedRows.Add(row);
}
// Export
foreach (GridViewRowInfo row in selectedRows)
{
row.IsSelected = true;
}
How to reproduce:
Public Class Form1
Sub New()
InitializeComponent()
Dim dataTable As New DataTable
dataTable.Columns.Add("Id", GetType(Integer))
dataTable.Columns.Add("Name", GetType(String))
dataTable.Columns.Add("IsValid", GetType(Boolean))
For i As Integer = 0 To 40
dataTable.Rows.Add(i, "Name " & i, i Mod 2 = 0)
Next
Me.RadGridView1.DataSource = dataTable
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Me.RadGridView1.TableElement.RowHeight = 20
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
Me.RadGridView1.PrintPreview()
End Sub
End Class
Workaround: before printing increase the row height or set RadGridView.AutoSizeRows = True
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
'Me.RadGridView1.TableElement.RowHeight = 24
Me.RadGridView1.AutoSizeRows = True
Me.RadGridView1.PrintPreview()
End Sub
Steps to reproduce: 1. Add a combobox column to a grid 2. Set DisplayMember, ValueMember and a data source to the column 3. Change a property in the data source that is used as value in the combo column You will see that the combo column will not display text for the item which value was changed