To reproduce: use the following code snippet. From the filtering box, when you select "Null" and then select "All", the following error occurs:
Item has already been added. Key in dictionary: '(Blanks)' Key being added: '(Blanks)'
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(1,"A");
dt.Rows.Add(2, "");
dt.Rows.Add(3, null);
dt.Rows.Add(4, "B");
dt.Rows.Add(5, "C");
dt.Rows.Add(6, "");
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.ShowHeaderCellButtons = true;
Workaround: this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;
RadListFilterDistinctValuesTable selectedValues;
private void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e)
{
RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
selectedValues = popup.MenuTreeElement.SelectedValues;
popup.MenuTreeElement.TreeView.NodeCheckedChanged += TreeView_NodeCheckedChanged;
}
private void TreeView_NodeCheckedChanged(object sender, TreeNodeCheckedEventArgs e)
{
if (e.Node.CheckState == Telerik.WinControls.Enumerations.ToggleState.Off)
{
if (selectedValues.Contains(e.Node.Text))
{
selectedValues.Remove(e.Node.Text);
}
}
}
I've attached a sample project. Here are the steps to repeat this issue:
1. Run the application
2. Click column A and drag it to the right to reorder it, scrolling the window as it goes
3. You are eventually presented with a NullReferenceException
You may have to try this several times with different columns before the problem manifests. I have found that moving just beyond the right edge of the main form and moving the mouse cursor up and down a little helps. I appears this problem only occurs in grids with many columns, so that fast scrolling can occur for multiple seconds when reordering columns.
Workaround:
Sub New()
InitializeComponent()
Me.RadGridView1.GridViewElement.RegisterService(New MyRadGridViewDragDropService(Me.RadGridView1.GridViewElement))
End Sub
Public Class MyRadGridViewDragDropService
Inherits RadGridViewDragDropService
Public Sub New(gridViewElement As RadGridViewElement)
MyBase.New(gridViewElement)
End Sub
Public Overrides ReadOnly Property Name As String
Get
Return "RadGridViewDragDropService"
End Get
End Property
Protected Overrides Sub PrepareDragHint(dropTarget As Telerik.WinControls.ISupportDrop)
Dim dragDropBehavior As IGridDragDropBehavior = Me.GetDragDropBehavior()
If dragDropBehavior Is Nothing OrElse dragDropBehavior.DragHint Is Nothing _
OrElse dragDropBehavior.DragHint.Image Is Nothing Then
Return
End If
Dim dropTargetItem As RadItem = TryCast(dropTarget, RadItem)
If dropTargetItem IsNot Nothing AndAlso dropTargetItem.ElementTree IsNot Nothing _
AndAlso Not dropTargetItem.ElementTree.Control.Equals(Me.GridViewElement.ElementTree.Control) Then
Return
End If
dragDropBehavior.UpdateDropContext(TryCast(Me.Context, ISupportDrag), dropTarget, Me.beginPoint)
Dim hintSize As Size = dragDropBehavior.GetDragHintSize(dropTarget)
Dim image As New Bitmap(hintSize.Width, hintSize.Height)
Dim temp As Graphics = Graphics.FromImage(image)
dragDropBehavior.DragHint.Paint(temp, New RectangleF(PointF.Empty, hintSize))
temp.Dispose()
Dim dragHintWindow As New RadLayeredWindow()
GetType(RadGridViewDragDropService).GetField("dragHintWindow", _
Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).SetValue(Me, dragHintWindow)
dragHintWindow.BackgroundImage = image
End Sub
End Class
To reproduce:
1. Add a RadGridView with a GridViewMultiComboBoxColumn. Enable the auto filter functionality for this column and add an appropriate FilterDescriptor to the RadMultiColumnComboBoxElement.
2. Using the keyboard arrows only (no mouse), navigate to the GridViewMultiComboBoxColumn.
3. Type "ba" by using the keyboard. The "b" is lost and only the "a" gets to the filter. I expect the filter to show "ba".
Workaround: use custom row behavior
public Form1()
{
InitializeComponent();
//register the custom row behavior
BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridDataRowBehavior());
}
public class CustomGridDataRowBehavior : GridDataRowBehavior
{
protected override bool ProcessAlphaNumericKey(KeyPressEventArgs keys)
{
bool result = base.ProcessAlphaNumericKey(keys);
if (this.IsInEditMode &&
(this.BeginEditMode == RadGridViewBeginEditMode.BeginEditOnKeystroke ||
this.BeginEditMode == RadGridViewBeginEditMode.BeginEditOnKeystrokeOrF2))
{
if (this.GridViewElement.ActiveEditor is RadMultiColumnComboBoxElement)
{
this.GridViewElement.ActiveEditor.Value = keys.KeyChar;
if (this.GridViewElement.IsInEditMode)
{
RadMultiColumnComboBoxElement mccb = (RadMultiColumnComboBoxElement)this.GridViewElement.ActiveEditor;
RadTextBoxItem textBoxItem = mccb.TextBoxElement.TextBoxItem;
textBoxItem.Clear();
textBoxItem.Text = keys.KeyChar.ToString();
textBoxItem.SelectionStart = 1;
textBoxItem.SelectionLength = 0;
}
return true;
}
}
return result;
}
}
To reproduce:
1. Run the attached application.
2. Click into the cell in Column One and expand the combo box
3. While the combo box is still expanded, right click on any header cell in the grid
Step 3 should result in a NullReferenceException
Workaround:
Friend Class MyGridHeaderCellElement
Inherits GridHeaderCellElement
Public Sub New(ByVal col As GridViewColumn, ByVal row As GridRowElement)
MyBase.New(col, row)
End Sub
Protected Overrides Sub ShowContextMenu()
If Me.ViewTemplate IsNot Nothing Then
MyBase.ShowContextMenu()
End If
End Sub
Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
Get
Return GetType(GridHeaderCellElement)
End Get
End Property
End Class
Private Sub radGridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs)
If Object.ReferenceEquals(e.CellType, GetType(GridHeaderCellElement)) Then
e.CellType = GetType(MyGridHeaderCellElement)
End If
End Sub
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:
private void Form1_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
radGridView1.AllowSearchRow = true;
radGridView1.DataSource = nwindDataSet.Categories;
radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.UseScrollbarsInHierarchy = true;
GridViewTemplate template = new GridViewTemplate();
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template.DataSource = nwindDataSet.Products;
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);
}
Workaround:
private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
if (this.radGridView1.CurrentRow != null)
{
if (this.radGridView1.CurrentRow.HierarchyLevel > 0)
{
tableElement.ScrollToRow((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
this.radGridView1.TableElement.EnsureRowVisible((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
tableElement.ScrollToRow(this.radGridView1.CurrentRow);
tableElement.EnsureRowVisible(this.radGridView1.CurrentRow);
}
}
}
To reproduce :
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
public RadForm1()
{
InitializeComponent();
radGridView1.DataSource = GetTable();
}
private void radButton1_Click(object sender, EventArgs e)
{
var exporter = new GridViewPdfExport(radGridView1);
exporter.FileExtension = "pdf";
exporter.ShowHeaderAndFooter = true;
exporter.LeftFooter = GridViewPdfExport.DatePrintedString;
exporter.FitToPageWidth = true;
exporter.PageMargins = new Padding(20, 15, 10, 10);
exporter.RunExport(@"C:\Users\dkaramfi\Desktop\test123.pdf", new PdfExportRenderer());
}
static DataTable GetTable()
{
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Name1", typeof(string));
table.Columns.Add("Name2", typeof(string));
table.Columns.Add("Name3", typeof(string));
table.Columns.Add("Name4", typeof(string));
table.Rows.Add(50, "Enebrel", "Sam", "Sam1", "Sam2", "Sam4", "Sam4");
table.Rows.Add(25, "Indocin", "David");
table.Rows.Add(50, "Enebrel", "Sam");
table.Rows.Add(10, "Hydralazine", "Christoff");
table.Rows.Add(21, "Combivent", "Janet");
table.Rows.Add(100, "Dilantin", "Melanie");
return table;
}
}
Workaround:
Leave the default margins.
To reproduce: make sure only the first row is selected then Shift select row 3.
DataTable dt = new DataTable();
dt.Columns.Add("Value", typeof(int));
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Description", typeof(string));
for (int index = 0; index < 15; index++)
{
dt.Rows.Add(new object[] { index % 5, DateTime.Now.AddSeconds(10), "Index = " + index });
}
radGridView1.DataSource = dt;
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.MultiSelect = true;
foreach (GridViewColumn col in this.radGridView1.Columns)
{
ConditionalFormattingObject obj = new ConditionalFormattingObject("Value",
ConditionTypes.Equal,
col.Index.ToString(),
"",
true);
obj.RowBackColor = Color.SkyBlue;
obj.RowForeColor = Color.Red;
obj.TextAlignment = ContentAlignment.MiddleRight;
obj.ApplyOnSelectedRows = false;
this.radGridView1.Columns[0].ConditionalFormattingObjectList.Add(obj);
}
Workaround: use the CellFormatting event to apply the desired formatting by using the API for overriding theme settings:
http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells
http://docs.telerik.com/devtools/winforms/telerik-presentation-framework/override-theme-settings-at-run-time
One should be able to set the maximum row height when the rows are auto sized and the visual styles are exported.
Until the new functionality becomes available you can use the workaround solution in the attached project.
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.
To reproduce: please refer to the attached gif file demonstrating how to reproduce the issue with the Demo application. Workaround: use the basic filtering.
To reproduce:
public class CustomGridViewCheckBoxColumn : GridViewCheckBoxColumn
{
}
CustomGridViewCheckBoxColumn col = new CustomGridViewCheckBoxColumn();
this.radGridView1.Columns.Add(col);
this.radGridView1.EnableFiltering = true;
1. Click the filter button and select "Custom"
2. Close the dialog.
Workaround:
this.radGridView1.CreateCompositeFilterDialog += radGridView1_CreateCompositeFilterDialog;
private void radGridView1_CreateCompositeFilterDialog(object sender, GridViewCreateCompositeFilterDialogEventArgs e)
{
e.Dialog = new CustomCompositeFilterForm();
}
public class CustomCompositeFilterForm : CompositeFilterForm
{
public override void Initialize(GridViewDataColumn dataColumn, FilterDescriptor filterDescriptor, bool useTypedEditors)
{
base.Initialize(dataColumn, filterDescriptor, useTypedEditors);
if (dataColumn is GridViewCheckBoxColumn)
{
RadGroupBox groupBox = this.Controls[0] as RadGroupBox;
groupBox.Controls.Remove(this.RightEditor);
groupBox.Controls.Remove(this.LeftEditor);
MethodInfo mi = typeof(CompositeFilterForm).GetMethod("InitializeCheckBoxEditors", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(this, null);
}
}
}
To reproduce: use the following code snippet and enter in the filter row one of the row values as it is shown in the screenshot:
this.radGridView1.EnableFiltering = true;
GridViewDateTimeColumn dateTimeColumn = new GridViewDateTimeColumn("DateTimeColumn");
dateTimeColumn.Format = DateTimePickerFormat.Custom;
dateTimeColumn.CustomFormat = "dd/MM/yyyy HH:mm:ss";
radGridView1.MasterTemplate.Columns.Add(dateTimeColumn);
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
for (int i = 0; i < 10; i++)
{
this.radGridView1.Rows.Add(DateTime.Now.AddDays(i));
}
Workaround: custom filtering: http://docs.telerik.com/devtools/winforms/gridview/filtering/custom-filtering
Steps to reproduce: - create a winforms project - create form (normal windows form, not telerik form) - create radgridview from toolbox - right click and open property builder - select mastertemplate - set viewdefinition = columngroups view - add 3-4 columns (textbox, combobox, etc...) - click ok button at the property builder - right click on the radgridview and open the property builder - rename the name and the header text of the first column - click ok button at the property builder
The event should be used to cancel copying for a single cell or override the value to be copied to the Clipboard.
Please refer to the attached screenshot.
To reproduce:
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 5; i++)
{
dt.Rows.Add(i, "Item" + i);
}
Random rand = new Random();
DataTable dt2 = new DataTable();
dt2.Columns.Add("Id", typeof(int));
dt2.Columns.Add("Name2", typeof(string));
dt2.Columns.Add("ParentId", typeof(int));
for (int i = 0; i < 20; i++)
{
dt2.Rows.Add(i, "Child Item" + i, rand.Next(0, 5));
}
radGridView1.DataSource = dt;
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dt2;
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.MasterTemplate.Templates.Add(template);
template.Columns["ParentId"].IsVisible = false;
GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "MasterDetail";
relation.ParentColumnNames.Add("Id");
relation.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation);
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.ShowHeaderCellButtons = true;
}
Workaround: change the Name property of the column in order to avoid duplicated columns:
template.Columns["Name"].Name = "Name2";
To reproduce
- Set the AutoSize and AutoSizeRows properties to true.
- Start editing a cell.
- Exception occurs.
Workaround:
class MyGrid : RadGridView
{
protected override void OnResize(EventArgs e)
{
//base.OnResize(e);
}
}
To reproduce:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
RadGridView1.AutoGenerateHierarchy = True
RadGridView1.DataSource = Me.NwindDataSet
RadGridView1.DataMember = "Categories"
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim style As New GridPrintStyle()
style.PrintHierarchy = True
style.HierarchyIndent = 20
style.ChildViewPrintMode = ChildViewPrintMode.SelectViewToPrint
Me.RadGridView1.PrintStyle = style
Me.RadGridView1.PrintPreview()
End Sub
Please refer to the attached gif file.
Workaround:
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Me.RadGridView1.PrintSettingsDialogFactory = New CustomGridViewPrintSettingsDialogFactory()
Dim style As New GridPrintStyle()
style.PrintHierarchy = True
style.HierarchyIndent = 20
style.ChildViewPrintMode = ChildViewPrintMode.SelectViewToPrint
Me.RadGridView1.PrintStyle = style
Me.RadGridView1.PrintPreview()
End Sub
Public Class CustomGridViewPrintSettingsDialog
Inherits GridViewPrintSettingsDialog
Sub New(document As RadPrintDocument)
MyBase.New(document)
End Sub
Protected Overrides Sub LoadSettings()
MyBase.LoadSettings()
Dim gridView As RadGridView = TryCast(Me.PrintDocument.AssociatedObject, RadGridView)
Me.printStyleSettingControl.PrintStyle.PrintHierarchy =gridView.PrintStyle.PrintHierarchy
End Sub
End Class
Public Class CustomGridViewPrintSettingsDialogFactory
Implements IPrintSettingsDialogFactory
Public Function CreateDialog(document As RadPrintDocument) As Form Implements IPrintSettingsDialogFactory.CreateDialog
Return New CustomGridViewPrintSettingsDialog(document)
End Function
End Class