Please refer to the attached gif file illustrating how to reproduce the error with the Demo application. Workaround: this.radGridView1.UseScrollbarsInHierarchy = true;
To reproduce: please refer to the attached gif file and sample project. The multiple newly added rows are selected only when the grid is not sorted.
Workaround: use Begin/EndUpdate when adding multiple rows
private void radButton1_Click(object sender, EventArgs e)
{
this.radGridView1.ClearSelection();
this.radGridView1.BeginUpdate();
for (int i = 0; i < 3; i++)
{
GridViewDataRowInfo row = new GridViewDataRowInfo(this.radGridView1.MasterView);
row.IsSelected = true;
row.IsCurrent = true;
row.Cells["Id"].Value = this.radGridView1.Rows.Count;
row.Cells["Name"].Value = "Row" + row.Cells["Id"].Value;
this.radGridView1.Rows.Add(row);
}
this.radGridView1.EndUpdate();
}
To reproduce: please refer o the attached sample project: 1.Click the left button. A new row will be added to the left grid and the grid will scroll to it. 2. Move the scrollbar back to the top and sort the ID column. 3. Click the left button again. A new row will be added but the grid won't scroll to it. Perform the same steps with the right grid. The grid scrolls as expected when you add a new row in a sorted grid. Workaround: use the Rows.Add method instead of Rows.AddNew.
To reproduce:
Sub New()
InitializeComponent()
Dim dt As New DataTable()
dt.Columns.Add("Price", GetType(System.Double))
dt.Columns.Add("Name", GetType(System.String))
dt.Columns.Add("Nr", GetType(System.Double))
For i As Integer = 0 To 49
dt.Rows.Add(i, "Data" & i, i)
Next
With Me.RadGridView1
.DataSource = dt
.Columns("Price").FormatString = "{0:C2}"
.Columns("Nr").FormatString = "{0:N1}"
.Columns("Price").ExcelExportType = Export.DisplayFormatType.Currency
'
.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
End With
Me.RadGridView1.Columns("Price").ExcelExportType = Export.DisplayFormatType.Currency
Me.RadGridView1.Columns("Nr").ExcelExportType = Export.DisplayFormatType.Custom
Me.RadGridView1.Columns("Nr").ExcelExportFormatString = "{0:N1}"
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim spreadStreamExport As New GridViewSpreadStreamExport(Me.RadGridView1)
spreadStreamExport.ExportVisualSettings = True
Dim fileName As String = "..\..\" + DateTime.Now.ToLongTimeString().Replace(":", "_").ToString() + ".xlsx"
spreadStreamExport.RunExport(fileName, New SpreadStreamExportRenderer())
Process.Start(fileName)
End Sub
Workaround:
Me.RadGridView1.Columns("Nr").ExcelExportType = Export.DisplayFormatType.Fixed
AddHandler spreadStreamExport.CellFormatting, AddressOf CellFormatting
Private Sub CellFormatting(sender As Object, e As SpreadStreamCellFormattingEventArgs)
If e.ExportCell.ColumnIndex = 2 Then
e.ExportCell.ExportFormat = "0.0"
End If
End Sub
To reproduce: The attached video shows how you can reproduce this. Workaround: Use the Properties window to remove summary rows.
Workaround: custom CompositeFilterForm
private void radGridView1_CreateCompositeFilterDialog(object sender, GridViewCreateCompositeFilterDialogEventArgs e)
{
e.Dialog = new MyCompositeFilterForm();
}
public class MyCompositeFilterForm : CompositeFilterForm
{
public override void Initialize(GridViewDataColumn dataColumn, Telerik.WinControls.Data.FilterDescriptor filterDescriptor, bool useTypedEditors)
{
base.Initialize(dataColumn, filterDescriptor, useTypedEditors);
if (dataColumn.Name == "Time")
{
RadDateTimePicker rEditor = (RadDateTimePicker)this.RightEditor;
rEditor.DateTimePickerElement.ShowTimePicker = true;
rEditor.DateTimePickerElement.CalendarSize = new Size(500, 250);
RadDateTimePicker lEditor = (RadDateTimePicker)this.LeftEditor;
lEditor.DateTimePickerElement.ShowTimePicker = true;
lEditor.DateTimePickerElement.CalendarSize = new Size(500, 250);
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
if (this.DialogResult == DialogResult.OK)
{
object leftValue = this.GetValueFromDateEditor(this.LeftEditor);
if (leftValue != null)
{
this.LeftDescriptor.Value = leftValue;
}
object rightValue = this.GetValueFromDateEditor(this.RightEditor);
if (rightValue != null)
{
this.RightDescriptor.Value = rightValue;
}
}
}
protected virtual object GetValueFromDateEditor(RadControl editorControl)
{
object value = null;
if (editorControl is RadDateTimePicker)
{
value = ((RadDateTimePicker)editorControl).Value;
return value;
}
return value;
}
}
To reproduce:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
for (int i = 0; i < 50; i++)
{
dt.Rows.Add(i, "Data" + i);
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.AutoSizeRows = false;
}
private void RadForm1_Load(object sender, EventArgs e)
{
this.radGridView1.Rows[5].MinHeight = 80;
this.radGridView1.Rows[5].MaxHeight = 100;
}
The Min/MaxHeight is not respected even when resizing the row.
Workaround: set the Height property.
Please refer to the attached sample project which result is illustrated in the provided screenshot. Workaround: this.radGridView1.ClearSelection(); this.radGridView1.CurrentRow = null; this.radGridView1.Rows[1].Cells[2].IsSelected = true;
Use attached project to reproduce. The video shows what steps you need to take. Workaround: Use CellEndEdit instead.
Use the attached project to reproduce. The video shows what steps you need to take.
To reproduce: please refer to the attached sample project and gif file.
Workaround:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor != null)
{
RadDateTimeEditorElement el = editor.EditorElement as RadDateTimeEditorElement;
if (el != null)
{
el.TextBoxElement.TextBoxItem.GotFocus -= TextBoxItem_GotFocus;
el.TextBoxElement.TextBoxItem.GotFocus += TextBoxItem_GotFocus;
}
}
}
private void TextBoxItem_GotFocus(object sender, EventArgs e)
{
RadTextBoxItem tb = sender as RadTextBoxItem;
if (tb != null)
{
tb.SelectionLength = 0;
}
}
To reproduce:
public RadForm1()
{
InitializeComponent();
this.radGridView1.MasterTemplate.Columns.Add(new GridViewDecimalColumn("ParentId"));
this.radGridView1.MasterTemplate.Columns.Add(new GridViewTextBoxColumn("ParentName"));
this.radGridView1.MasterTemplate.Rows.Add(1, "Item" + 1);
this.radGridView1.MasterTemplate.Rows.Add(2, "Item" + 2);
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
for (int i = 0; i < 10; i++)
{
GridViewTemplate template = new GridViewTemplate();
template.AllowAddNewRow = false;
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template.Caption = "Tab" + i;
template.Columns.Add(new GridViewDecimalColumn("Id"));
template.Columns.Add(new GridViewTextBoxColumn("Name"));
this.radGridView1.MasterTemplate.Templates.Add(template);
template.HierarchyDataProvider = new GridViewEventDataProvider(template);
}
this.radGridView1.RowSourceNeeded += radGridView1_RowSourceNeeded;
}
private void radGridView1_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{
for (int i = 0; i < 10; i++)
{
GridViewRowInfo row = e.Template.Rows.NewRow();
row.Cells["Id"].Value = e.ParentRow.Cells["ParentId"].Value;
row.Cells["name"].Value = "child row" + i;
e.SourceCollection.Add(row);
}
}
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
GridDetailViewCellElement cell = e.CellElement as GridDetailViewCellElement;
if (cell != null)
{
RadPageViewStripElement strip = cell.PageViewElement as RadPageViewStripElement;
strip.StripButtons = StripViewButtons.LeftScroll | StripViewButtons.RightScroll;
}
}
If you have just one row on the master level, the strip buttons don't navigate the tabs.
Workaround: add a dummy row that is hidden:
private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
if (e.RowElement.RowInfo == this.radGridView1.Rows.Last())
{
e.RowElement.RowInfo.Height = 1;
e.RowElement.RowInfo.MinHeight = 1;
e.RowElement.RowInfo.MaxHeight = 1;
}
else
{
e.RowElement.RowInfo.Height = 25;
e.RowElement.RowInfo.MinHeight = 25;
e.RowElement.RowInfo.MaxHeight = 25;
}
}
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 200000
dt.Rows.Add(index, "Item" & index)
Next
Me.RadGridView1.DataSource = dt
Me.RadGridView1.MultiSelect = True
Me.RadGridView1.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim sw As New Stopwatch
sw.Start()
Dim mi As MethodInfo = GetType(GridViewSelectedCellsCollection).GetMethod("BeginUpdate", BindingFlags.Instance Or BindingFlags.NonPublic)
mi.Invoke(Me.RadGridView1.MasterTemplate.SelectedCells, Nothing)
For Each row As GridViewDataRowInfo In Me.RadGridView1.Rows
row.Cells("Name").IsSelected = True
Next
Dim mi2 As MethodInfo = GetType(GridViewSelectedCellsCollection).GetMethod("EndUpdate", BindingFlags.Instance Or BindingFlags.NonPublic)
mi2.Invoke(Me.RadGridView1.MasterTemplate.SelectedCells, New Object() {True})
sw.Stop()
RadMessageBox.Show(sw.ElapsedMilliseconds)
End Sub
To reproduce:
DataTable table;
public RadForm1()
{
InitializeComponent();
table = GetTable();
radGridView1.DataSource = table;
}
private void radButton1_Click(object sender, EventArgs e)
{
var changes = table.GetChanges();
if (changes == null)
{
Console.WriteLine("No Changes");
}
else
{
Console.WriteLine("Saved");
foreach (DataRow item in changes.Rows)
{
Console.WriteLine(item.RowState.ToString());
}
}
table.AcceptChanges();
}
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("Date", typeof(DateTime));
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
table.AcceptChanges();
return table;
}
Workaround:
(this.radGridView1.CurrentRow.DataBoundItem as IEditableObject).EndEdit();
To reproduce: use the following code snippet, save the layout and load it afterwards. You will notice that only the master and the first child template are successfully loaded.
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, "Parent" + i);
}
this.radGridView1.MasterTemplate.DataSource = dt;
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
//child level 1
GridViewTemplate template = new GridViewTemplate();
template.DataSource = GetData(5, 20, 0, 5);
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.MasterTemplate.Templates.Add(template);
GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "ParentChild";
relation.ParentColumnNames.Add("Id");
relation.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation);
//child level 2
GridViewTemplate template2 = new GridViewTemplate();
template2.DataSource = GetData(20, 40, 5, 20);
template2.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template.Templates.Add(template2);
GridViewRelation relation2 = new GridViewRelation(template);
relation2.ChildTemplate = template2;
relation2.RelationName = "ParentChild";
relation2.ParentColumnNames.Add("Id");
relation2.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation2);
//child level 3
GridViewTemplate template3 = new GridViewTemplate();
template3.DataSource = GetData(40, 100, 20, 40);
template3.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template2.Templates.Add(template3);
GridViewRelation relation3 = new GridViewRelation(template2);
relation3.ChildTemplate = template3;
relation3.RelationName = "ParentChild";
relation3.ParentColumnNames.Add("Id");
relation3.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation3);
//child level 4
GridViewTemplate template4 = new GridViewTemplate();
template4.DataSource = GetData(100, 200, 40, 100);
template4.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template3.Templates.Add(template4);
GridViewRelation relation4 = new GridViewRelation(template3);
relation4.ChildTemplate = template4;
relation4.RelationName = "ParentChild";
relation4.ParentColumnNames.Add("Id");
relation4.ChildColumnNames.Add("ParentId");
radGridView1.Relations.Add(relation4);
}
private object GetData(int from, int to, int parentFrom, int parentTo)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("ParentId", typeof(int));
Random rand = new Random();
for (int i = from; i < to; i++)
{
dt.Rows.Add(i, "Child" + i, rand.Next(parentFrom, parentTo));
}
return dt;
}
private void radButton1_Click(object sender, EventArgs e)
{
string s = "default.xml";
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
dialog.Title = "Select a xml file";
if (dialog.ShowDialog() == DialogResult.OK)
{
s = dialog.FileName;
}
this.radGridView1.SaveLayout(s);
}
private void radButton2_Click(object sender, EventArgs e)
{
string s = "default.xml";
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
dialog.Title = "Select a xml file";
if (dialog.ShowDialog() == DialogResult.OK)
{
s = dialog.FileName;
}
this.radGridView1.LoadLayout(s);
}
Workaround: grid templates for the inner levels are recreated after loading the layout. Their DataSource is null and the existing relations points to the old templates. Clear the relations and setup them again with the new child template instances.
Workaround:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
((GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).FormatString = "{0: yyyy-MM-dd hh:mm:ss.fff tt}";
}
private DataTable 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));
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
}
return dt;
}
}
public class MyRadGridView : RadGridView
{
public override string ThemeClassName
{
get
{
return typeof(RadGridView).FullName;
}
}
protected override RadGridViewElement CreateGridViewElement()
{
return new MyRadGridViewElement();
}
}
public class MyRadGridViewElement : RadGridViewElement
{
protected override Type ThemeEffectiveType
{
get
{
return typeof(MyRadGridViewElement);
}
}
protected override MasterGridViewTemplate CreateTemplate()
{
return new MyMasterGridViewTemplate();
}
}
public class MyMasterGridViewTemplate : MasterGridViewTemplate
{
public override void Copy()
{
base.Copy();
GridViewCellInfo[] cells = null;
if (this.SelectionMode == GridViewSelectionMode.CellSelect)
{
cells = new GridViewCellInfo[this.SelectedCells.Count];
this.SelectedCells.CopyTo(cells, 0);
}
else if (this.SelectionMode == GridViewSelectionMode.FullRowSelect)
{
GridViewDataRowInfo row = this.SelectedRows[0] as GridViewDataRowInfo;
if (this.SelectedRows.Count == 1 && row.ViewTemplate.CurrentColumn != null)
{
cells = new GridViewCellInfo[row.Cells.Count];
for (int i = 0; i < row.Cells.Count; i++)
{
cells[i] = row.Cells[i];
}
}
}
if (Clipboard.GetData(DataFormats.Text) != null)
{
string data = Clipboard.GetData(DataFormats.Text).ToString();
if (data != string.Empty && cells != null)
{
var values = data.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder sb = new StringBuilder();
foreach (string value in values)
{
DateTime date;
if (DateTime.TryParse(value, out date))
{
string baseFormat = "yyyy-MM-dd HH:mm tt";
foreach (var cell in cells)
{
if (cell.ColumnInfo is GridViewDateTimeColumn && ((DateTime)cell.Value).ToString(baseFormat) == date.ToString(baseFormat))
{
sb.Append(string.Format(((GridViewDateTimeColumn)cell.ColumnInfo).FormatString, cell.Value) + "\t");
break;
}
}
}
else
{
sb.Append(value + "\t");
}
}
Clipboard.Clear();
Clipboard.SetData(DataFormats.Text, sb.ToString());
}
}
}
}
To reproduce:
public Form1()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
this.radGridView1.Columns.Add("column " + i);
}
int charsCount = 5;
for (int i = 0; i < 20; i++)
{
this.radGridView1.Rows.Add(new string('0', charsCount), new string('1', charsCount),
new string('2', charsCount), new string('3', charsCount), new string('4', charsCount),
new string('5', charsCount), new string('6', charsCount), new string('7', charsCount),
new string('8', charsCount), new string('9', charsCount));
}
HtmlViewDefinition view = new HtmlViewDefinition();
view.RowTemplate.Rows.Add(new RowDefinition());
view.RowTemplate.Rows.Add(new RowDefinition());
view.RowTemplate.Rows.Add(new RowDefinition());
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Column 0", 0, 1, 1));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Column 1", 0, 1, 3));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Column 2", 0, 1, 1));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Column 3", 0, 1, 1));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Column 7", 0, 1, 1));
view.RowTemplate.Rows[1].Cells.Add(new CellDefinition("Column 4", 0, 1, 2));
view.RowTemplate.Rows[1].Cells.Add(new CellDefinition("Column 5", 0, 2, 1));
view.RowTemplate.Rows[1].Cells.Add(new CellDefinition("Column 8", 0, 1, 1));
view.RowTemplate.Rows[2].Cells.Add(new CellDefinition("Column 6", 0, 2, 1));
view.RowTemplate.Rows[2].Cells.Add(new CellDefinition("Column 9", 0, 1, 1));
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.ViewDefinition = view;
}
Workaround:
private void radGridView1_SizeChanged(object sender, EventArgs e)
{
this.radGridView1.MasterTemplate.Refresh();
}