BindingList<Item> items = new BindingList<Item>();
public Form1()
{
InitializeComponent();
for (int i = 0; i < 20; i++)
{
items.Add(new Item(i % 4, "Item" + i, "Type" + i % 2));
}
this.radGridView1.DataSource = items;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public Item(int id, string name, string type)
{
this.Id = id;
this.Name = name;
this.Type = type;
}
}
private void radButton1_Click(object sender, EventArgs e)
{
items.Insert(0, new Item(2, "Test", "Type0"));
}
WORKAROUND I:
GridViewSynchronizationService.SuspendEvent(this.radGridView1.MasterTemplate, KnownEvents.CurrentChanged);
Item item = new Item(2, "Test", "Type0");
items.Insert(0, item);
GridViewSynchronizationService.ResumeEvent(this.radGridView1.MasterTemplate, KnownEvents.CurrentChanged);
foreach (GridViewRowInfo row in this.radGridView1.Rows)
{
if (row.DataBoundItem == item)
{
this.radGridView1.CurrentRow = row;
break;
}
}
WORKAROUND II:
this.radGridView1.Rows.CollectionChanged += Rows_CollectionChanged;
this.radGridView1.GroupExpanding+=radGridView1_GroupExpanding;
List<GridViewRowInfo> expandedGroups = new List<GridViewRowInfo>();
private void radGridView1_GroupExpanding(object sender, GroupExpandingEventArgs e)
{
if (!e.IsExpanded && shouldCollapse)
{
expandedGroups.Add(e.DataGroup.GroupRow);
}
}
bool shouldCollapse = false;
private void radButton1_Click(object sender, EventArgs e)
{
shouldCollapse = true;
items.Insert(0, new Item(2, "Test", "Type0"));
}
private void Rows_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{
if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)
{
this.radGridView1.CurrentRow = e.NewItems[0] as GridViewRowInfo;
this.radGridView1.CurrentRow.IsSelected = true;
GridViewRowInfo parent = this.radGridView1.CurrentRow.Parent as GridViewRowInfo;
if (parent != null)
{
parent.IsExpanded = true;
}
if (shouldCollapse)
{
shouldCollapse = false;
foreach (GridViewRowInfo r in expandedGroups)
{
if (!ContainsParentRow(parent, r))
{
r.IsExpanded = false;
}
}
expandedGroups.Clear();
}
}
}
private bool ContainsParentRow(GridViewRowInfo parent, GridViewRowInfo r)
{
GridViewGroupRowInfo group = r as GridViewGroupRowInfo;
if (group != null)
{
foreach (GridViewRowInfo childRow in group.ChildRows)
{
return ContainsParentRow(parent, childRow);
}
}
return parent == r.Parent;
}
Workaround: set up the templates from code, http://www.telerik.com/help/winforms/gridview-overview.html
To reproduce:
1. Add a RadTreeView and a RadGridView
2. Use the following code snippet.
3. Select a node from the RadtreeView.
4. Activate the editor for the new row in RadGridView.
5. While the grid editor is active, select a new node in the tree.
public Form1()
{
InitializeComponent();
this.radGridView1.MasterTemplate.AddNewBoundRowBeforeEdit = true;
}
public class ClassA
{
public int Id { get; set; }
public string Name { get; set; }
public string Grade { get; set; }
public ClassA()
{
}
public ClassA(int id, string name, string grade)
{
this.Id = id;
this.Name = name;
this.Grade = grade;
}
}
public class ClassB
{
public int NewID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ClassB()
{
}
public ClassB(int id, string firstName, string lastName)
{
this.NewID = id;
this.FirstName = firstName;
this.LastName = lastName;
}
}
private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
if (radGridView1.DataSource is BindingList<ClassA>)
{
this.radGridView1.Columns.Clear();
this.radGridView1.DataSource = null;
BindingList<ClassB> list = new BindingList<ClassB>() { new ClassB(1, "John", "Wick") };
this.radGridView1.DataSource = list;
}
else
{
this.radGridView1.DataSource = null;
BindingList<ClassA> list = new BindingList<ClassA>() { new ClassA(1,"John", "A+") };
this.radGridView1.Columns.Clear();
this.radGridView1.DataSource = list;
}
}
Workaround: this.radGridView1.MasterTemplate.AddNewBoundRowBeforeEdit = false;
Workaround: create a custom GridCheckBoxHeaderCellElement and override the Attach method
public class MyGridCheckBoxHeaderCellElement : GridCheckBoxHeaderCellElement
{
public MyGridCheckBoxHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
{
}
protected override Type ThemeEffectiveType {
get { return typeof(GridHeaderCellElement); }
}
public override void Attach(GridViewColumn data, object context)
{
if (((GridViewCheckBoxColumn)data).EnableHeaderCheckBox) {
base.Attach(data, context);
} else {
this.CheckBox.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
}
}
public Form1()
{
InitializeComponent();
this.radGridView1.CreateCell += radGridView1_CreateCell;
}
private void radGridView1_CreateCell(object sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridCheckBoxHeaderCellElement)) {
e.CellElement = new MyGridCheckBoxHeaderCellElement(e.Column, e.Row)
}
}
To reproduce:
private RadGridView radGridView1;
public Form1()
{
InitializeComponent();
radGridView1 = new RadGridView() { Dock = DockStyle.Fill };
Controls.Add(radGridView1);
List<Item> items = new List<Item>();
for (int i = 0; i < 10; i++)
{
items.Add(new Item(i, "Item" + i, DateTime.Now.AddDays(i)));
}
radGridView1.AutoGenerateColumns = true;
this.radGridView1.DataSource = items;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.CustomFiltering += radGridView1_CustomFiltering;
radGridView1.EnableCustomFiltering = true;
}
void radGridView1_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
{
e.Handled = false;
e.Visible = true;
var item = (Item)e.Row.DataBoundItem;
if (item == null)
return;
if (item.Name.EndsWith("Item"))
{
e.Handled = true;
e.Visible = false;
}
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public Nullable<DateTime> Date { get; set; }
public Item(int id, string name, Nullable<DateTime> date)
{
this.Id = id;
this.Name = name;
this.Date = date;
}
}
Workaround:
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
this.radGridView1.MasterTemplate.Refresh();
}
To reproduce:
Me.RadGridView1.MultiSelect = True
Private Sub RadGridView1_CellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) _
Handles RadGridView1.CellFormatting
If e.Row.IsSelected Then
e.CellElement.BackColor = Color.LimeGreen
e.CellElement.DrawFill = True
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
Else
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
End If
End Sub
Step 1: Select a few rows with the mouse click in combination with the CTRL key.
Step 2: The rows are selected correctly and the desired green back color is applied. Release the CTRL Key.
Step 3: Click with the mouse on a different row in the grid.
Result: All previously selected rows but the last current row keep the green back color.
Workaround:
Sub New()
InitializeComponent()
Me.RadGridView1.MultiSelect = True
AddHandler Me.RadGridView1.SelectionChanging, AddressOf SelectionChanging
AddHandler Me.RadGridView1.SelectionChanged, AddressOf SelectionChanged
End Sub
Private Sub RadGridView1_CellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) _
Handles RadGridView1.CellFormatting
e.CellElement.DrawFill = True
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
If e.Row.IsSelected Then
e.CellElement.BackColor = Color.LimeGreen
Else
e.CellElement.BackColor = Color.Yellow
End If
End Sub
Private Sub SelectionChanged(sender As Object, e As EventArgs)
For Each r As GridViewRowInfo In selectedRows
r.InvalidateRow()
Next
selectedRows.Clear()
End Sub
Dim selectedRows As New List(Of GridViewRowInfo)
Private Sub SelectionChanging(sender As Object, e As GridViewSelectionCancelEventArgs)
For Each r As GridViewRowInfo In Me.RadGridView1.SelectedRows
selectedRows.Add(r)
Next
End Sub
To reproduce:
private void Form1_Load(object sender, EventArgs e)
{
this.customersTableAdapter.Fill(this.nwindDataSet.Customers);
this.radGridView1.DataSource = this.customersBindingSource;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
foreach (GridViewColumn col in this.radGridView1.Columns)
{
col.MinWidth = 100;
}
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact"));
view.ColumnGroups.Add(new GridViewColumnGroup("Details"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact"));
view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["CompanyName"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactName"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactTitle"]);
view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Address"]);
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["City"]);
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Country"]);
view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Phone"]);
view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Fax"]);
radGridView1.ViewDefinition = view;
}
Please refer to the attached gif file illustrating the behavior when no ColumnGroupsViewDefinition is applied. The horizontal scroll-car should appear as well when the grid's width is less than the total MinWidth of all columns in case of ColumnGroupsViewDefinition.
Workaround: use GridViewAutoSizeColumnsMode.None and handle the RadGridView.SizeChanged event where you can adjust manually the Width of the visible columns on a way to simulate GridViewAutoSizeColumnsMode.Fill. Here is a sample approach:
private void Form1_Load(object sender, EventArgs e)
{
this.customersTableAdapter.Fill(this.nwindDataSet.Customers);
this.radGridView1.DataSource = this.customersBindingSource;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.None;
foreach (GridViewColumn col in this.radGridView1.Columns)
{
col.MinWidth = 100;
}
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact"));
view.ColumnGroups.Add(new GridViewColumnGroup("Details"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact"));
view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["CompanyName"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactName"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactTitle"]);
view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Address"]);
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["City"]);
view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Country"]);
view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Phone"]);
view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Fax"]);
radGridView1.ViewDefinition = view;
radGridView1.SizeChanged += radGridView1_SizeChanged;
}
private void radGridView1_SizeChanged(object sender, EventArgs e)
{
int totalMinimumWidth = 0;
int columnsCount = ColumnsCountWidth(out totalMinimumWidth);
int delta = this.radGridView1.Width - totalMinimumWidth;
AdjustColumnWidth(delta / columnsCount);
}
private void AdjustColumnWidth(int widthToAdd)
{
ColumnGroupsViewDefinition view = this.radGridView1.ViewDefinition as ColumnGroupsViewDefinition;
if (view == null)
{
return;
}
foreach (GridViewColumnGroup group in view.ColumnGroups)
{
AdjustColumnsInGroup(widthToAdd, group);
}
}
private void AdjustColumnsInGroup(int widthToAdd, GridViewColumnGroup group)
{
if (group.Groups.Count == 0)
{
foreach (GridViewColumnGroupRow row in group.Rows)
{
foreach (GridViewColumn col in row.Columns)
{
col.Width += widthToAdd;
}
}
}
else
{
foreach (GridViewColumnGroup g in group.Groups)
{
AdjustColumnsInGroup(widthToAdd, g);
}
}
}
private int ColumnsCountWidth(out int totalMinWidth)
{
int columnsCount = 0;
totalMinWidth = 0;
ColumnGroupsViewDefinition view = this.radGridView1.ViewDefinition as ColumnGroupsViewDefinition;
if (view == null)
{
return this.radGridView1.Columns.Count;
}
foreach (GridViewColumnGroup group in view.ColumnGroups)
{
columnsCount = IterateGroups(columnsCount, group, ref totalMinWidth);
}
return columnsCount;
}
private static int IterateGroups(int columnsCount, GridViewColumnGroup group, ref int totalMinWidth)
{
int count = columnsCount;
if (group.Groups.Count == 0)
{
foreach (GridViewColumnGroupRow row in group.Rows)
{
count += row.Columns.Count;
foreach (GridViewColumn col in row.Columns)
{
totalMinWidth += col.Width;
}
}
}
else
{
foreach (GridViewColumnGroup g in group.Groups)
{
count = IterateGroups(count, g, ref totalMinWidth);
}
}
return count;
}
Please refer to the attached screenshot. Workaround: either select the RadGridView node in the Property Builder, or use the VS design time or control Smart Tag to set DataSource
To reproduce : - Set conditional formatting for all grid cells. - Iterate all grid cells and set their value. Workaround: Use Begin/End update block.
To reproduce: - Add grid with several columns and set their AllowResize property to false. - Set the FitWidthMode to FitPageWidth. - Print the grid and you will notice that some of the columns are cut off. Workaround: - Set the AllowResize property to true before printing.
To reproduce:
- Enter a value in the search row (make sure you will have several results)
- Enter a letter in the filtering row. The filetring row will lose the focus.
Workaround:
public class MyGridViewSearchRowInfo : GridViewSearchRowInfo
{
public MyGridViewSearchRowInfo(GridViewInfo viewInfo) : base(viewInfo)
{
}
public override void SelectNextSearchResult()
{
GridViewSystemRowInfo systemRow = this.ViewTemplate.MasterTemplate.CurrentRow as GridViewSystemRowInfo;
if (systemRow != null && this.ViewTemplate.MasterTemplate.Owner.EditorManager.IsInEditMode)
{
return;
}
base.SelectNextSearchResult();
}
}
//change the default row like this
void radGridView1_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
{
if (e.RowInfo is GridViewSearchRowInfo)
{
e.RowInfo = new MyGridViewSearchRowInfo(e.ViewInfo);
}
}
To reproduce: following the illustrated steps: http://screencast.com/t/D2TCpU2zo Workaround: set up the hierarchy programmatically.
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: GridViewMultiComboBoxColumn supplierColumn = new GridViewMultiComboBoxColumn(); supplierColumn.SyncSelectionWithText = true; supplierColumn.Name = "SupplierColumn"; supplierColumn.HeaderText = "Supplier"; supplierColumn.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown; supplierColumn.AutoCompleteMode = AutoCompleteMode.Append; supplierColumn.DataSource = this.suppliersBindingSource; supplierColumn.ValueMember = "SupplierID"; supplierColumn.DisplayMember = "ContactName"; supplierColumn.FieldName = "SupplierID"; supplierColumn.Width = 200; this.radGridView1.Columns.Add(supplierColumn); Select the new row and try to enter some text that is not valid and press Enter. You will notice the new row is added with the last valid auto-completed value. Workaround: cancel the UserAddingRow event if the entered text is not valid.
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: 1. Populate RadGridView with data 2. Export the grid by using the SpreadExport 3. Open the produce Excel file and select some cells to generate a chart in Excel. You will notice that it is not possible to create a complete chart with the selected data. Workaround: use the ExportToExcelML >> http://www.telerik.com/help/winforms/gridview-exporting-data-export-to-excel-via-excelml-format.html
To reproduce: - Set the cell's BackColor in an entire column. - Set the cell's Forecolor in another column. - Change the grid size to the columns are hidden and then shown again. Workaround: Change similar properties for all the cells where the Style property is used or use CellFormatting.