Description: When you pin data rows from the child template to PinnedRowPosition.Top, it does not affect the row. However, when you pin the certain row to PinnedRowPosition.Bottom, the behavior is correct. The same issue is detected for the header rows from the child template.
Workaround: use the CellValidating event
To reproduce:
Sub New()
InitializeComponent()
Dim dt As New DataTable()
For index = 1 To 13
If index = 4 Then
dt.Columns.Add("Col" & index, Type.GetType("System.Int32"))
Else
dt.Columns.Add("Col" & index)
End If
Next
Dim rand As New Random
For index = 1 To 9000
Dim newRow As DataRow = dt.NewRow()
For Each col As DataColumn In dt.Columns
If col.ColumnName = "Col4" Then
newRow(col.ColumnName) = rand.Next(2, 1000).ToString()
Else
newRow(col.ColumnName) = "Data" & index.ToString() & "." & dt.Columns.IndexOf(col).ToString()
End If
Next
dt.Rows.Add(newRow)
Next
Me.RadGridView1.DataSource = dt
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Me.RadGridView1.Columns.RemoveAt(3)
Dim list As New List(Of CustomerMaster)
For index = 1 To 1000
list.Add(New CustomerMaster((index + 1), "Name" & (1000 - index + 1).ToString()))
Next
Dim CustomerMaster_IDColumn As GridViewComboBoxColumn = New GridViewComboBoxColumn
With CustomerMaster_IDColumn
.Name = "CustomerMaster_ID"
.HeaderText = "Customer Master"
.DataSource = list
.ValueMember = "Id"
.DisplayMember = "Name"
.FieldName = "Col4"
.Width = 200
.DisplayMemberSort = True
.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
End With
Me.RadGridView1.Columns.Insert(3, CustomerMaster_IDColumn)
End Sub
Public Class CustomerMaster
Private _id As String
Private _name As String
Public Sub New(id As String, name As String)
Me._id = id
Me._name = name
End Sub
Public Property Id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
To reproduce:
Add a RadGridView. Create a DataTable with 3 columns with data type - Decimal. To the last column set the following expression - "column1 + column2". Add some rows with some values. Turn on excel like filtering - http://www.telerik.com/help/winforms/gridview-filtering-excel-like-filtering.html. Subscribe to the CellValueChanged event and add the following code:
if (this.radGridView1.CurrentRow.DataBoundItem != null)
{
((DataRowView)this.radGridView1.CurrentRow.DataBoundItem).Row.EndEdit(); // force row subtotal update
}
Start the application and filter the last column by some of the available values. Change a value in one of the first two cells. You will notice that the last cell's value is not updated although it is updated in the data table. This behavior does not occur when the grid is not filtered.
To reproduce: use the code from our demo application for Custom Filtering. Instead of Customers table, bind the grid to Orders or another table with 1000+ rows.
Resolution: You can surround the row operation in Begin/EndUpdate(false) and remove the InvalidateRow method. The Custom Filtering example in our demo Application is updated for better performance or you can use the following code snippet:
For example:
private void radGridView1_CustomFiltering(object sender, Telerik.WinControls.UI.GridViewCustomFilteringEventArgs e)
{
if (string.IsNullOrEmpty(this.radTextBox1.Text))
{
this.radGridView1.BeginUpdate();
e.Visible = true;
for (int i = 0; i < this.radGridView1.ColumnCount; i++)
{
e.Row.Cells[i].Style.Reset();
}
//e.Row.InvalidateRow();
this.radGridView1.EndUpdate(false);
return;
}
this.radGridView1.BeginUpdate();
e.Visible = false;
for (int i = 0; i < this.radGridView1.ColumnCount; i++)
{
string text = e.Row.Cells[i].Value.ToString();
if (text.IndexOf(this.radTextBox1.Text, 0, StringComparison.InvariantCultureIgnoreCase) >= 0)
{
e.Visible = true;
e.Row.Cells[i].Style.CustomizeFill = true;
e.Row.Cells[i].Style.DrawFill = true;
e.Row.Cells[i].Style.BackColor = Color.FromArgb(201, 252, 254);
}
else
{
e.Row.Cells[i].Style.Reset();
}
}
//e.Row.InvalidateRow();
this.radGridView1.EndUpdate(false);
}
To reproduce: - Add GridViewComboBoxColumn to a grid. - Set the DisplayMemeber property like this: column1.DisplayMember = "AddInfo.Status";
To reproduce:
Add a RadGridView to a form, dont dock it. Use the following code to add the rows, columns and the definition:
this.Grid.Columns.Add("Old");
this.Grid.Columns.Add("New");
Start the application and you will see that you cannot scroll to the end, horizontally.
Workaround:
Use the following code on a button click or execute it in a timer a few millisecond after the form has loaded in order to update the scrollbar's maximum value accordingly:
int width = 0;
foreach (var col in this.Grid.Columns)
{
width += col.Width;
}
this.Grid.TableElement.HScrollBar.Maximum = width - this.Grid.TableElement.HScrollBar.SmallChange - this.Grid.TableElement.RowHeaderColumnWidth;
Steps to reproduce:
1. expand a parent row
2. remove the first child row (e.g. 'Jon Smith') by selecting the child row and press the button at the top
3. remove the second (last) child row (in this case 'Pete van Dijk') the same way
Here is the code snippet:
public partial class Form1 : Form
{
private List<Department> _departments;
public Form1()
{
InitializeComponent();
SetGridParentColumns();
SetGridChildTemplate();
InitData();
grid.RowSourceNeeded += grid_RowSourceNeeded;
}
private void InitData()
{
_departments = new List<Department>(2);
Department dep1 = new Department() { DepartmentId = 1, Name = "Accounting" };
Department dep2 = new Department() { DepartmentId = 2, Name = "Finance" };
Employee emp1 = new Employee() { DepartmentId = 1, EmployeeId = 1, FirsName = "John", LastName = "Smith" };
Employee emp2 = new Employee() { DepartmentId = 1, EmployeeId = 2, FirsName = "Pete", LastName = "van Dijk" };
Employee emp3 = new Employee() { DepartmentId = 2, EmployeeId = 3, FirsName = "Mark", LastName = "Smith" };
Employee emp4 = new Employee() { DepartmentId = 2, EmployeeId = 4, FirsName = "Jan", LastName = "Janssen" };
dep1.Employees = new List<Employee>() { emp1, emp2 };
dep2.Employees = new List<Employee>() { emp3, emp4 };
_departments.Add(dep1);
_departments.Add(dep2);
grid.DataSource = _departments;
grid.AllowAddNewRow = false;
grid.BestFitColumns();
}
private void SetGridParentColumns()
{
grid.AutoGenerateColumns = false;
grid.Columns.Add("DepartmentId", "DepartmentId", "DepartmentId");
grid.Columns.Add("Name", "Name", "Name");
}
private void SetGridChildTemplate()
{
grid.Templates.Clear();
GridViewTemplate childTemplate = new GridViewTemplate();
childTemplate.Columns.Add("EmployeeId");
childTemplate.Columns.Add("DepartmentId");
childTemplate.Columns.Add("FirstName");
childTemplate.Columns.Add("LastName");
grid.Templates.Add(childTemplate);
childTemplate.HierarchyDataProvider = new GridViewEventDataProvider(childTemplate);
}
private void grid_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{
Department dep = e.ParentRow.DataBoundItem as Department;
foreach (Employee employee in dep.Employees)
{
GridViewRowInfo gridRow = e.Template.Rows.NewRow();
gridRow.Cells["EmployeeId"].Value = employee.EmployeeId;
gridRow.Cells["DepartmentId"].Value = employee.DepartmentId;
gridRow.Cells["FirstName"].Value = employee.FirsName;
gridRow.Cells["LastName"].Value = employee.LastName;
e.SourceCollection.Add(gridRow);
}
e.Template.AllowAddNewRow = false;
e.Template.BestFitColumns();
}
private void btnRemoveChildRow_Click(object sender, EventArgs e)
{
GridViewRowInfo row = grid.SelectedRows[0];
if (row.ViewTemplate.Parent == null)
return; //department (parent) row, so don't remove it
int employeeId = Convert.ToInt32(row.Cells["EmployeeId"].Value);
int departmentId = Convert.ToInt32(row.Cells["DepartmentId"].Value);
Department dep = GetDepartment(departmentId);
dep.RemoveEmployee(employeeId);
row.ViewTemplate.Refresh();
}
private Department GetDepartment(int departmentId)
{
foreach (Department dep in _departments)
if (dep.DepartmentId == departmentId)
return dep;
return null;
}
}
public class Department
{
public int DepartmentId { get; set; }
public string Name { get; set; }
public List<Employee> Employees { get; set; }
public void RemoveEmployee(int employeeId)
{
Employee empToRemove = null;
foreach (Employee emp in Employees)
{
if (emp.EmployeeId == employeeId)
{
empToRemove = emp;
break;
}
}
if (empToRemove != null)
Employees.Remove(empToRemove);
}
}
public class Employee
{
public int DepartmentId { get; set; }
public int EmployeeId { get; set; }
public string FirsName { get; set; }
public string LastName { get; set; }
}
Workaround: use the ViewInfo.Refresh method instead of the ViewTemplate.Refresh method
1.Different naming of RadGridView templates (in the Smart tag - Relations section and in the Property Builder - Relations section) is confusing. 2.Column reordering via drag and drop in the same template. This action will change the object order of the grid. All changes are shown in the Preview section: I can select columns listed in the object tree, but cannot drag them up or down within a template. The only way I can reorder columns in the property builder appears to be by dragging them left or right in the preview pane. 3.Column moving via drag and drop from one template to another template. This action will change the object order of the grid. All changes are shown in the Preview section: I cannot move columns in the object tree from one template to another. 4.Template reordering via drag and drop. All changes are shown in the Preview section: drag and drop operation for templates in not allowed. 5.There is a right-click context menu for the object tree, with the following options: "Edit", "Expand / Collapse", "New", "Delete". Under no circumstances do the options "Edit" and "New" ever become enabled. 6.The preview pane displays a preview of the columns for the master template. When the child template is selected, the preview pane still shows a preview of the columns for the master template. As such, it is not possible to reorder columns for child templates in the preview pane. 7.When you set up the RadGridView hierarchy automatically at design time and open the Property Builder, all templates are visualized. It is possible to select/deselect columns from the different templates. It is possible to change columns names. However, when you press the OK button and close the Property Builder, try to reopen it. As a result you will notice that all columns from all child templates are selected and all columns contain the default names, no matter what changes were performed. Refer to the corresponding help article http://www.telerik.com/help/winforms/gridview-design-time-support-property-builder.html
To reproduce:
-add hierarchical RadGriddView with one parent template and several child templates;
-set TableElement.PageViewMode to PageViewMode.ExplorerBar;
Selection for different templates is not performed correcltly.
Workaround: use custom GridDataRowBehavior:
BaseGridBehavior gridBehavior = this.radGridView1.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo),
new RowSelectionGridBehavior());
public class RowSelectionGridBehavior : GridDataRowBehavior
{
protected override bool OnMouseDownLeft(MouseEventArgs e)
{
GridDataRowElement row = this.GetRowAtPoint(e.Location) as GridDataRowElement;
if (row != null)
{
row.RowInfo.IsSelected = true;
row.RowInfo.IsCurrent = true;
return true;
}
return base.OnMouseDownLeft(e);
}
}
To reproduce:
-add a RadGridView and use the following code:
public Form1()
{
InitializeComponent();
GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn("ComboBox column");
comboColumn.DataSource = new List<string>() { "first", "second", "third" };
radGridView1.Columns.Add(comboColumn);
radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
}
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDropDownListEditor dropDownEditor = radGridView1.ActiveEditor as RadDropDownListEditor;
RadDropDownListEditorElement dropDownEditorElement = dropDownEditor.EditorElement as RadDropDownListEditorElement;
dropDownEditorElement.SelectedIndex = 0;
}
If you try to add a new row in the grid, the first item in the RadDropDownListEditor is selected. If you do not make any selection changes and press Enter key, the new row will not be added.
Workaround: use the DefaultValuesNeeded event for initializing RadDropDownListEditorElement's selectin
To reproduce: 1. Add RadGridView with 2 columns 2. Sort first column. Then sort second column. 3. Break in the SortChanged event handler method 4. e.NewItems[0].PropertyName is 'column1' and e.OldItems[0].PropertyName is 'column2', the values are swapped
To reproduce:
-add a RadGridView and bind it to Northwind.Customers datatable.
-try to edit a random row and change its CustomerID cell to an already existing one.
Workaround: use custom GridViewDataRowInfo:
public class CustomRowInfo : GridViewDataRowInfo
{
public CustomRowInfo(GridViewInfo viewInfo) : base(viewInfo)
{
}
protected override bool OnEndEdit()
{
IEditableObject dataItem = this.DataBoundItem as IEditableObject;
if (dataItem != null)
{
try
{
dataItem.EndEdit();
}
catch (Exception ex)
{
this.ViewTemplate.SetError(new GridViewCellCancelEventArgs(null,null, null), ex);
}
}
return base.OnEndEdit();
}
}
Workaround:
public Form1()
{
InitializeComponent();
radGridView1.CreateCell += radGridView1_CreateCell;
}
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridDataCellElement))
{
e.CellElement = new CustomDataCell(e.Column,e.Row);
}
}
public class CustomDataCell : GridDataCellElement
{
public CustomDataCell(GridViewColumn column, GridRowElement row) : base(column, row)
{
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left &&
this.AllowRowReorder &&
this.ViewTemplate.AllowRowReorder &&
Cursor.Current != Cursors.SizeNS)
{
base.OnMouseDown(e);
}
}
}
To reproduce:
- add RadGridView and use the following code:
public Form1()
{
InitializeComponent();
DataTable source = new DataTable();
string colName = string.Empty;
for (var i = 0; i < 10; i++)
{
colName = "col" + i.ToString();
this.Grid.Columns.Add(new GridViewTextBoxColumn(colName));
source.Columns.Add(new DataColumn(colName));
}
this.Grid.DataSource = source;
}
- Run the project, click over the grid and press PageUp key. As a result NullReferenceException is thrown.
Workaround: use custom BaseGridBehavior:
this.radGridView1.GridBehavior = new CustomGridBehavior();
public class CustomGridBehavior : BaseGridBehavior
{
protected override bool ProcessPageUpKey(KeyEventArgs keys)
{
GridTableElement tableElement = (GridTableElement)this.GridViewElement.CurrentView;
GridViewRowInfo firstScrollableRow = GetFirstScrollableRow(tableElement, true);
RadScrollBarElement scrollBar = tableElement.VScrollBar;
if (this.GridViewElement.CurrentRow == firstScrollableRow && firstScrollableRow!=null)
{
int height = (int)tableElement.RowScroller.ElementProvider.GetElementSize(firstScrollableRow).Height;
int newValue = scrollBar.Value - scrollBar.LargeChange + height + tableElement.RowScroller.ScrollOffset;
scrollBar.Value = Math.Max(newValue, scrollBar.Minimum);
tableElement.UpdateLayout();
firstScrollableRow = GetFirstScrollableRow(tableElement, false);
}
this.GridViewElement.Navigator.SelectRow(firstScrollableRow);
this.NavigateToPage(firstScrollableRow, keys.KeyData);
return true;
}
}
To reproduce:
- add a RadGridView with one column - GridViewMultiComboBoxColumn;
- set DataSource property of the column;
- subscribe to the CellValidating and use the following code:
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
e.Cancel = true;
}
Run the application and select a value from the GridViewMultiComboBoxColumn. When pressing Enter key, InvalidCastException is thrown.
Workaround:
radGridView1.EditorManager.CloseEditorWhenValidationFails = true;
To reproduce:
Add a TabControl and two tabs. In the second tab add a RadGridView and in the Load event of the form set the SplitMode property of the grid. You will notice that it will not have effect until grouping or other similar action has been performed.
Workaround:
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("column1");
dt.Columns.Add("column2");
RadGridView1.DataSource = dt;
this.RadGridView1.VisibleChanged += Visible_Changed;
}
private void Visible_Changed(object sender, EventArgs e)
{
if (this.RadGridView1.Visible & !this.RadGridView1.SplitMode.Equals(Telerik.WinControls.UI.RadGridViewSplitMode.Horizontal)) {
RadGridView1.SplitMode = Telerik.WinControls.UI.RadGridViewSplitMode.Horizontal;
}
}
To reproduce:
Add a RadGridView and use the following code to populate it:
for (int i = 0; i < 15; i++)
{
this.grid.Columns.Add(string.Format("Column {0}", i));
}
for (int i = 0; i < this.grid.Columns.Count * 15; i++)
{
this.grid.Rows.AddNew();
}t
Set the theme to TelerikMetroTouch.
Scroll somewhere below the middle leave the scrollbar and leave the grid with the mouse. You will notice that the value of the scrollbar will change.
Workaround:
Subscribe to the RadPropertyChanging event of the TableElement:
RadGridView1.TableElement.RadPropertyChanging += Property_Changing;
void TableElement_RadPropertyChanging(object sender, RadPropertyChangingEventArgs args)
{
args.Cancel = args.Property == GridTableElement.RowHeightProperty ||
args.Property == GridTableElement.TableHeaderHeightProperty ||
args.Property == GridTableElement.GroupHeaderHeightProperty ||
args.Property == GridTableElement.FilterRowHeightProperty;
}
Extend the cell elements with a button(s) (via decorator for example) which will be visible without putting the grid in edit mode. The buttons should not be visible by default and their visibility will be controlled via property of the column. These buttons can be RadButtonElements which will not hurt the performance. Their purpose will be to inform the end user that some cell is a combo or a date time cell without having to open its editor in advance. When the button is clicked, the corresponding action should be executed e.g. for combo cell, open the editor and show the popup; for spin cell open the editor and perform the click of the desired button. Same goes for the rest of the editors - mccb, color, browse, date time, etc.