To reproduce:
Public Class RadForm1
Public RadGridView1 As RadGridView
Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
CreateGrid()
FormatGrid()
SetDataSource()
End Sub
Private Sub CreateGrid()
Try
RadGridView1 = New RadGridView
Me.Controls.Add(RadGridView1)
Catch ex As Exception
MessageBox.Show(Me, ex.Message)
End Try
End Sub
Private Sub FormatGrid()
Dim col As GridViewTextBoxColumn
With RadGridView1
col = New GridViewTextBoxColumn
With col
.FieldName = "FieldID"
'NOTE: Comment out NullValue = "" to prevent the unhandled exception
.NullValue = ""
End With
.Columns.Add(col)
End With
End Sub
Private Sub SetDataSource()
Dim table As DataTable = Nothing
Dim row As DataRow = Nothing
table = New DataTable("GridList")
table.Columns.Add("FieldID", GetType(System.Guid))
row = table.NewRow
row("FieldID") = Guid.Empty
table.Rows.Add(row)
RadGridView1.DataSource = table
End Sub
End Class
Workaround:
Comment this line
NullValue = ""
Please refer to the attached sample project. The ResizeColumnsProportionally.gif illustrates the correct behavior of columns resizing. However, if you make a certain column with fixed size, the columns resizing is not proportional any more. The ColumnsWidthNOTAdjustedProportionally.gif demonstrates better the wrong behavior. Workaround: handle the SizeChanged event and adjust the columns' width property programmatically in order to obtain the desired widths.
Until the new functionality becomes available you can use the workaround solution in the attached project.
Excel does not support dates prior to 1/1/1900, however, we could export such dates as simple strings: https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
How to reproduce:
public partial class Form1 : RadForm
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
private object GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Bool", typeof(bool));
dt.Columns.Add("Date", typeof(DateTime));
DateTime date = new DateTime(1850, 1, 1);
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(i, "Name " + i, i % 2 == 0, date.AddYears(i));
}
return dt;
}
FieldInfo fi;
private void radButton1_Click(object sender, EventArgs e)
{
//Old Export using the ExcelML format
this.fi = typeof(Telerik.WinControls.UI.Export.ExcelML.CellElement).GetField("_dataElement", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
string fileName = @"..\..\data.xls";
exporter.RunExport(fileName);
//New export utilizing the SpreadProcessing libraries
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
spreadExporter.RunExport(@"..\..\data.xlsx", exportRenderer);
}
}
Workaround: handle the CellFormatting event
public partial class Form1 : RadForm
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
private object GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Bool", typeof(bool));
dt.Columns.Add("Date", typeof(DateTime));
DateTime date = new DateTime(1850, 1, 1);
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(i, "Name " + i, i % 2 == 0, date.AddYears(i));
}
return dt;
}
FieldInfo fi;
private void radButton1_Click(object sender, EventArgs e)
{
//Old Export using the ExcelML format
this.fi = typeof(Telerik.WinControls.UI.Export.ExcelML.CellElement).GetField("_dataElement", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
exporter.ExcelCellFormatting += Exporter_ExcelCellFormatting;
string fileName = @"..\..\data.xls";
exporter.RunExport(fileName);
//New export utilizing the SpreadProcessing libraries
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
spreadExporter.CellFormatting += SpreadExporter_CellFormatting;
SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
spreadExporter.RunExport(@"..\..\data.xlsx", exportRenderer);
}
private void SpreadExporter_CellFormatting(object sender, Telerik.WinControls.Export.CellFormattingEventArgs e)
{
if (e.GridRowIndex >= 1 && e.GridCellInfo.ColumnInfo is GridViewDateTimeColumn && ((DateTime)e.GridCellInfo.Value).Year < 1900)
{
Telerik.Windows.Documents.Spreadsheet.Model.CellSelection cell = e.CellSelection as Telerik.Windows.Documents.Spreadsheet.Model.CellSelection;
cell.SetValue(e.GridCellInfo.Value.ToString());
}
}
private void Exporter_ExcelCellFormatting(object sender, Telerik.WinControls.UI.Export.ExcelML.ExcelCellFormattingEventArgs e)
{
if (e.GridRowIndex > -1 && e.GridCellInfo.ColumnInfo is GridViewDateTimeColumn && ((DateTime)e.GridCellInfo.Value).Year < 1900)
{
DataElement data = new DataElement();
data.DataItem = e.GridCellInfo.Value.ToString();
this.fi.SetValue(e.ExcelCellElement, data);
}
}
}
Workaround: handle the GridViewPdfExport.CellFormatting event and apply the column`s format string
Public Class Form1
Sub New()
InitializeComponent()
Me.RadGridView1.DataSource = Me.GetData()
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Dim decimalColumn = DirectCast(Me.RadGridView1.Columns("Money"), GridViewDecimalColumn)
decimalColumn.DecimalPlaces = 0
decimalColumn.FormatString = "{0:C0}"
Dim dateTimeColumn = DirectCast(Me.RadGridView1.Columns("Date"), GridViewDateTimeColumn)
dateTimeColumn.FormatString = "{0:D}"
End Sub
Private Function GetData() As Object
Dim dataTable As New DataTable()
dataTable.Columns.Add("Id", GetType(Integer))
dataTable.Columns.Add("Name", GetType(String))
dataTable.Columns.Add("Money", GetType(Decimal))
dataTable.Columns.Add("Date", GetType(DateTime))
For i As Integer = 0 To 999
dataTable.Rows.Add(i, "Name " & i, i * 10, DateTime.Now.AddDays(i))
Next
Return dataTable
End Function
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim pdfExporter = New GridViewPdfExport(Me.RadGridView1)
AddHandler pdfExporter.CellFormatting, AddressOf pdfExporter_CellFormatting
Dim renderer = New PdfExportRenderer()
Dim fileName As String = "..\..\exported-grid.pdf"
pdfExporter.RunExport(fileName, renderer)
End Sub
Private Sub pdfExporter_CellFormatting(sender As Object, e As PdfExportCellFormattingEventArgs)
If e.RowIndex > -1 Then
e.CellElement.Text = TryCast(RadDataConverter.Instance.Format(e.Row.Cells(e.ColumnIndex).Value, GetType(String), e.Column), String)
End If
End Sub
End Class
To reproduce: if you pin a calculator or a hyperlink column you will notice that the cells belonging to these columns remain white. However, the cells from other column types have a light blue/gray fill color for pinned state.
Workaround:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.Column.IsPinned)
{
e.CellElement.BackColor = Color.FromArgb(235, 244, 252);
}
else
{
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
To reproduce: please refer to the attached gif file and sample project.
Workaround: when you set the DrawFill property to true, specify the BackColor to the desired one and reset for the rest of the cells.
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.Column.Name == "ProductName" && e.Row is GridViewDataRowInfo)
{
if (e.CellElement.Value.ToString().Contains("C"))
{
e.CellElement.DrawFill = true;
e.CellElement.BackColor = Color.Yellow;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.ForeColor = Color.OliveDrab;
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
To reproduce:
- Add a RadGridView and a button to a blank form.
- Subscribe to CellValidating event from the grid and set the cancel property of the CellValidatingEventArgs to true upon some condition.
- Add click event handler for the button and print a message in it.
- Start the application and enter some invalid data in the grid cell, then click the button.
- The code from the button's event handler is executed.
Workaround use a flag to determine when to execute the corresponding button code:
bool validating = false;
void radGridView1_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
{
if (e.Value.ToString().Length < 5)
{
e.Cancel = true;
validating = true;
e.Row.ErrorText = "Validation error!";
}
else
{
validating = false;
}
}
private void radButton1_Click(object sender, EventArgs e)
{
if (!validating)
{
Debug.WriteLine("Executed");
}
}
To reproduce: please refer to the attached screenshot. Workaround: add the FilterDescriptor programmatically: https://docs.telerik.com/devtools/winforms/gridview/filtering/setting-filters-programmatically-(simple-descriptors)
To reproduce:
this.radGridView1.Columns.Add("FIRST CELL ID A");
this.radGridView1.Rows.Add("405-55-214-41763");
this.radGridView1.Rows.Add("405-55-214-46682");
this.radGridView1.Rows.Add("405-55-214-46682");
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.MultiSelect = true;
this.radGridView1.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
Please refer to the attached gif file illustrating better the text moving.
Workaround:
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
e.CellElement.BorderBottomWidth = 2;
e.CellElement.BorderRightWidth = 2;
e.CellElement.BorderTopWidth = 2;
e.CellElement.BorderLeftWidth = 2;
}
To reproduce: this.radGridView1.SummaryRowsBottom.Insert(0, summaryRowItem2); this.radGridView1.SummaryRowsBottom.Move(2, 0); Workaround: Remove all items and add them back with a spesific order.
How to reproduce: check the attached project and video
Bind the grid to the following DataTable:
DataTable dt = new DataTable();
dt.Columns.Add("X.Y");
dt.Columns.Add("X");
dt.Rows.Add("Data X.Y", "Data X");
this.radGridView1.DataSource = dt;
You will notice that the second column "X" is missing.
Note: if you change the order of adding the columns, both columns will be added.
The new mode should allow copying of single cells even when having the SelectionMode set to FullRowSelect. The attached project features a possible workaround.
How to reproduce:
Create a grid with enabled filtering and open the excel-like filter popup of a DateTime column.
Workaround:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.FilterPopupInitialized += RadGridView1_FilterPopupInitialized;
}
private void RadGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
RadDateFilterPopup popup = e.FilterPopup as RadDateFilterPopup;
if (popup != null && popup.Width < 300)
{
popup.Width += 100;
popup.Height += 100;
}
}
private object GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Bool", typeof(bool));
dt.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(i, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(1));
}
return dt;
}
}
How to reproduce:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.FilterPopupRequired += RadGridView1_FilterPopupRequired;
GridViewDateTimeColumn date = this.radGridView1.Columns["Date"] as GridViewDateTimeColumn;
date.DataType = typeof(DateTime);
date.FilteringMode = GridViewTimeFilteringMode.Date;
}
private void RadGridView1_FilterPopupRequired(object sender, Telerik.WinControls.UI.FilterPopupRequiredEventArgs e)
{
if (e.Column.GetType().Name == "GridViewDateTimeColumn")
{
RadListFilterPopup popup = new RadListFilterPopup(e.Column, true);
e.FilterPopup = popup;
}
}
private object GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Bool", typeof(bool));
DateTime date = DateTime.Now;
for (int i = 0; i < 1500; i++)
{
dt.Rows.Add(i, "Name " + i, date.AddDays(i), i % 2 == 0);
}
return dt;
}
Workaround: custom RadListFilterPopup
public class MyRadListFilterPopup : RadListFilterPopup
{
public MyRadListFilterPopup(GridViewDataColumn dataColumn, bool groupedDateValues)
: base(dataColumn, groupedDateValues)
{ }
protected override void OnButtonOkClick(EventArgs e)
{
FilterOperator filterOperator = FilterOperator.IsEqualTo;
IRadListFilterElement listFilterElement = typeof(RadListFilterPopup).GetField("listFilterElement", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).
GetValue(this) as IRadListFilterElement;
switch (listFilterElement.SelectedMode)
{
case ListFilterSelectedMode.All:
filterOperator = FilterOperator.None;
break;
case ListFilterSelectedMode.Null:
filterOperator = FilterOperator.IsNull;
break;
case ListFilterSelectedMode.NotNull:
filterOperator = FilterOperator.IsNotNull;
break;
}
if (filterOperator != FilterOperator.IsEqualTo)
{
SetFilterOperator(filterOperator);
this.ClosePopup(RadPopupCloseReason.CloseCalled);
}
else
{
CompositeFilterDescriptor compositeFilterDescriptor = new CompositeFilterDescriptor();
compositeFilterDescriptor.PropertyName = base.DataColumn.Name;
compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.Or;
foreach (DictionaryEntry entry in listFilterElement.SelectedValues)
{
foreach (object value in (ArrayList)entry.Value)
{
FilterDescriptor descriptor;
if (base.DataColumn is GridViewDateTimeColumn || base.DataColumn.DataType == typeof(DateTime) ||
base.DataColumn.DataType == typeof(DateTime?))
{
descriptor = new DateFilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, (DateTime?)value, false);
}
else
{
descriptor = new FilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, value);
}
compositeFilterDescriptor.FilterDescriptors.Add(descriptor);
}
}
base.FilterDescriptor = compositeFilterDescriptor;
OnFilterConfirmed();
}
}
}
To reproduce:
Sub New()
InitializeComponent()
Dim dt As New DataTable
dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
For index = 1 To 1000
dt.Rows.Add(index, "Item" & index)
Next
Me.RadGridView1.DataSource = dt
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim pdfFile As String = "..\..\exportedFile.pdf"
Dim pdfExporter As New GridViewPdfExport(Me.RadGridView1)
pdfExporter.ShowHeaderAndFooter = True
pdfExporter.FitToPageWidth = True
AddHandler pdfExporter.PdfExported, AddressOf pdfExporter_PdfExported
Dim renderer As New PdfExportRenderer()
pdfExporter.RunExport(pdfFile, renderer)
Process.Start(pdfFile)
End Sub
Private Sub pdfExporter_PdfExported(sender As Object, e As System.EventArgs)
Dim pdfFile As String = "..\..\exportedFile.pdf"
Dim document As RadFixedDocument
Dim provider As Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider = New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider()
Using stream As Stream = File.OpenRead(pdfFile)
document = provider.Import(stream) '<==== Error Found
For Each page As RadFixedPage In document.Pages
Dim editor As FixedContentEditor = New FixedContentEditor(page)
editor.Position.Translate(page.Size.Width / 2, page.Size.Height - 50)
Dim pageNum As Integer = document.Pages.IndexOf(page) + 1
editor.DrawText(pageNum + " of " + document.Pages.Count)
Next
End Using
Using output As Stream = File.OpenWrite(pdfFile)
provider.Export(document, output) '<==== Error Found
End Using
Process.Start(pdfFile)
End Sub
Workaround: use the PdfExportRenderer.PdfExporting event where you have access to the document and you can make any customizations to it:
Dim pdfFile As String = "..\..\exportedFile.pdf"
Dim pdfExporter As New GridViewPdfExport(Me.RadGridView1)
pdfExporter.ShowHeaderAndFooter = True
pdfExporter.FitToPageWidth = True
Dim renderer As New PdfExportRenderer()
AddHandler renderer.PdfExporting, AddressOf PdfExporting
pdfExporter.RunExport(pdfFile, renderer)
Private Sub PdfExporting(sender As Object, e As PdfExportingEventArgs)
Dim document As RadFixedDocument = e.Document
Dim provider As Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider = New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider()
For Each page As RadFixedPage In document.Pages
Dim editor As FixedContentEditor = New FixedContentEditor(page)
editor.Position.Translate(page.Size.Width / 2, page.Size.Height - 50)
Dim pageNum As Integer = document.Pages.IndexOf(page) + 1
editor.DrawText(pageNum & " of " & document.Pages.Count)
Next
End Sub
How to reproduce:
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.FillData();
this.radGridView1.DataSource = this.dt;
this.radGridView1.EnableSorting = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
this.radGridView1.SortChanged += radGridView1_SortChanged;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
public void FillData()
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 30; i++)
{
dt.Rows.Add(i, "Item" + i);
}
}
private void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.ItemChanged)
{
SortDescriptor s = e.NewItems[0] as SortDescriptor;
string sortOperator = "";
if (s.Direction == ListSortDirection.Ascending)
{
sortOperator = "ASC";
}
else
{
sortOperator = "DESC";
}
dt.DefaultView.Sort = s.PropertyName + " " + sortOperator;
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
dt.DefaultView.Sort = "";
}
}
}
Workaround:
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.FillData();
this.radGridView1.DataSource = this.dt;
this.radGridView1.EnableSorting = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.CellBeginEdit += RadGridView1_CellBeginEdit;
this.radGridView1.CellEndEdit += RadGridView1_CellEndEdit;
}
private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
if (e.Row is GridViewFilteringRowInfo)
{
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
}
}
private void RadGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
{
if (e.Row is GridViewFilteringRowInfo)
{
this.radGridView1.MasterTemplate.DataView.BypassSort = false;
}
}
public void FillData()
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 30; i++)
{
dt.Rows.Add(i, "Item" + i);
}
}
}