To reproduce:
- Subscribe to the CellClick event
- Click several times in the grid with the right mouse button.
- At some point, the CellClick event will be executed.
Workaround:
- Use the Click event:
private void RadGridView1_Click(object sender, EventArgs e)
{
var args = e as MouseEventArgs;
if (args.Button == MouseButtons.Left)
{
var clickedCell = radGridView1.ElementTree.GetElementAtPoint(args.Location) as GridDataCellElement;
if (clickedCell != null)
{
//add your code here
}
}
}
Please refer to the attached sample project and select a new value in the drop down.
Workaround: change the PageSize in the RadDropDownListElement.PopupClosed event:
public sealed class PageSizeDropdownHeaderCellElement : GridHeaderCellElement
{
public PageSizeDropdownHeaderCellElement(GridViewColumn col, GridRowElement row) : base(col, row)
{
TextAlignment = ContentAlignment.TopCenter;
Alignment = ContentAlignment.TopCenter;
}
private RadDropDownListElement _dropDownListElement;
protected override void CreateChildElements()
{
base.CreateChildElements();
_dropDownListElement = new RadDropDownListElement();
if (_dropDownListElement != null && _dropDownListElement.DataSource == null)
{
_dropDownListElement = new RadDropDownListElement();
_dropDownListElement.BindingContext = new BindingContext();
_dropDownListElement.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
_dropDownListElement.Items.Clear();
_dropDownListElement.Items.Add(new RadListDataItem("10", 10) { Selected = true });
_dropDownListElement.Items.Add(new RadListDataItem("25", 25));
_dropDownListElement.Items.Add(new RadListDataItem("50", 50));
_dropDownListElement.Items.Add(new RadListDataItem("100", 100));
_dropDownListElement.Items.Add(new RadListDataItem("All", -1));
_dropDownListElement.Margin = new Padding(15, 0, 0, 0);
_dropDownListElement.StretchHorizontally = true;
_dropDownListElement.NotifyParentOnMouseInput = false;
_dropDownListElement.Popup.MouseClick += Popup_MouseClick;
_dropDownListElement.PopupClosed += _dropDownListElement_PopupClosed;
this.Children.Add(_dropDownListElement);
}
}
RadListVisualItem elementUnderMouse;
private void Popup_MouseClick(object sender, MouseEventArgs e)
{
elementUnderMouse = _dropDownListElement.Popup.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
}
private void _dropDownListElement_PopupClosed(object sender, RadPopupClosedEventArgs args)
{
if (elementUnderMouse == null)
{
return;
}
if (_dropDownListElement.SelectedIndex == -1)
return;
var pageSize = Convert.ToInt32(elementUnderMouse.Data.Value);
if (pageSize == -1)
{
pageSize = GridControl.RowCount;
}
else
{
pageSize = pageSize <= GridControl.RowCount ? pageSize : GridControl.RowCount;
}
this.RowInfo.Tag = pageSize;
GridControl.PageSize = pageSize;
elementUnderMouse = null;
}
protected override void SetContentCore(object value)
{
if (_dropDownListElement != null && this.RowInfo.Tag != null)
{
this._dropDownListElement.SelectedValue = (int)this.RowInfo.Tag;
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data is ActionColumn && context is GridTableHeaderRowElement;
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridHeaderCellElement);
}
}
}
The problematic themes are:
Aqua
HighContrastBlack
VisualStudio2012Dark
VisualStudio2012Light
Windows8
How to reproduce:
private void RadForm1_Load(object sender, EventArgs e)
{
var theme = new Windows8Theme();
ThemeResolutionService.ApplicationThemeName = "Windows8";
GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn();
textBoxColumn.Name = "Test";
this.radGridView1.Columns.Add(textBoxColumn);
for (int i = 0; i < 100; i++)
{
this.radGridView1.Rows.AddNew();
}
}
Workaround:
private void RadForm1_Load(object sender, EventArgs e)
{
var theme = new Windows8Theme();
ThemeResolutionService.ApplicationThemeName = "Windows8";
GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn();
textBoxColumn.Name = "Test";
this.radGridView1.Columns.Add(textBoxColumn);
this.radGridView1.BeginUpdate();
for (int i = 0; i < 100; i++)
{
this.radGridView1.Rows.AddNew();
}
this.radGridView1.EndUpdate();
int lastRow = this.radGridView1.Rows.Count - 1;
this.radGridView1.Rows[lastRow].IsCurrent = true;
}
To reproduce:
GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn("Col 1");
textBoxColumn1.FieldName = "col1";
radGridView1.MasterTemplate.Columns.Add(textBoxColumn1);
GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn("Col 2");
textBoxColumn2.FieldName = "col2";
textBoxColumn2.FormatString = "{0:d}";
radGridView1.MasterTemplate.Columns.Add(textBoxColumn2);
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(DateTime));
for (int i = 0; i < 10; i++)
{
dt.Rows.Add("Item" + i, DateTime.Now.AddDays(i));
}
this.radGridView1.AutoGenerateColumns = false;
this.radGridView1.DataSource = dt;
Right click the row header cell and select Copy. The following exception occurs although we don't have a GridViewDateTimeColumn : System.InvalidCastException was unhandled
HResult=-2147467262
Message=Unable to cast object of type 'Telerik.WinControls.UI.GridViewTextBoxColumn' to type 'Telerik.WinControls.UI.GridViewDateTimeColumn'.
Source=Telerik.WinControls.GridView
StackTrace:
at Telerik.WinControls.UI.MasterGridViewTemplate.CopyRows(String format, Boolean cut, Boolean cutOperation, StringBuilder content)
at Telerik.WinControls.UI.MasterGridViewTemplate.ProcessContent(String format, Boolean cut, Boolean cutOperation)
at Telerik.WinControls.UI.MasterGridViewTemplate.CopyContent(Boolean cut)
at Telerik.WinControls.UI.MasterGridViewTemplate.Copy()
at Telerik.WinControls.UI.GridDataRowElement.copyItem_Click(Object sender, EventArgs e)
at Telerik.WinControls.RadElement.OnClick(EventArgs e)
at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
at Telerik.WinControls.UI.RadMenuItem.OnClick(EventArgs e)
at Telerik.WinControls.RadElement.DoClick(EventArgs e)
at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at Telerik.WinControls.RadControl.WndProc(Message& m)
at Telerik.WinControls.UI.RadPopupControlBase.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at _1075342CopyText.Program.Main() in d:\Projects\1075342CopyText_Binding\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Workaround: use a GridViewDateTimeColumn
To reproduce:
Sub New()
InitializeComponent()
Dim dt1 As New DataTable
dt1.Columns.Add("Id", GetType(Integer))
dt1.Columns.Add("Name", GetType(String))
For index = 1 To 20
dt1.Rows.Add(index, "Parent" & index)
Next
Me.RadGridView1.MasterTemplate.DataSource = dt1
Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
Dim dt2 As New DataTable
dt2.Columns.Add("Id", GetType(Integer))
dt2.Columns.Add("Name", GetType(String))
dt2.Columns.Add("ParentId", GetType(Integer))
Dim dt3 As New DataTable
dt3.Columns.Add("Id", GetType(Integer))
dt3.Columns.Add("Name", GetType(String))
dt3.Columns.Add("ParentId", GetType(Integer))
For index = 1 To 20
If index Mod 2 = 0 Then
dt2.Rows.Add(index, "Child1." & index, index)
If index Mod 4 = 0 Then
dt3.Rows.Add(index, "Child2." & index, index)
End If
ElseIf index Mod 3 = 0 Then
dt3.Rows.Add(index, "Child2." & index, index)
Else
dt3.Rows.Add(index, "Child2." & index, index)
End If
Next
Dim template As New GridViewTemplate()
template.DataSource = dt2
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
RadGridView1.MasterTemplate.Templates.Add(template)
Dim relation As New GridViewRelation(RadGridView1.MasterTemplate)
relation.ChildTemplate = template
relation.RelationName = "FirstChild"
relation.ParentColumnNames.Add("Id")
relation.ChildColumnNames.Add("ParentId")
RadGridView1.Relations.Add(relation)
Dim template2 As New GridViewTemplate()
template2.DataSource = dt3
template2.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
RadGridView1.MasterTemplate.Templates.Add(template2)
Dim relation2 As New GridViewRelation(RadGridView1.MasterTemplate)
relation2.ChildTemplate = template2
relation2.RelationName = "SecondChild"
relation2.ParentColumnNames.Add("Id")
relation2.ChildColumnNames.Add("ParentId")
RadGridView1.Relations.Add(relation2)
AddHandler Me.RadGridView1.ChildViewExpanding, AddressOf ChildViewExpanding
End Sub
Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) _
Handles RadGridView1.ViewCellFormatting
Dim cell As GridDetailViewCellElement = TryCast(e.CellElement, GridDetailViewCellElement)
Dim expanderCell As GridGroupExpanderCellElement = TryCast(e.CellElement, GridGroupExpanderCellElement)
If expanderCell IsNot Nothing AndAlso TypeOf e.CellElement.RowElement Is GridDataRowElement Then
Dim hierarchyRow As GridViewHierarchyRowInfo = DirectCast(expanderCell.RowInfo, GridViewHierarchyRowInfo)
If Not IsExpandable(hierarchyRow) Then
expanderCell.Expander.Visibility = Telerik.WinControls.ElementVisibility.Hidden
Else
expanderCell.Expander.Visibility = Telerik.WinControls.ElementVisibility.Visible
End If
ElseIf cell IsNot Nothing Then
Dim hierarchyRow As GridViewHierarchyRowInfo = DirectCast(DirectCast(cell.RowInfo, GridViewDetailsRowInfo).Owner, _
GridViewHierarchyRowInfo)
For i As Integer = 0 To cell.PageViewElement.Items.Count - 1
Dim item As RadPageViewItem = cell.PageViewElement.Items(i)
Dim viewInfo As GridViewInfo = hierarchyRow.Views(i)
item.Text = "Child Template " & i
If viewInfo.ChildRows.Count = 0 Then
If i = 0 AndAlso i < cell.PageViewElement.Items.Count - 1 Then
cell.PageViewElement.Items(i + 1).IsSelected = True
End If
item.Visibility = Telerik.WinControls.ElementVisibility.Hidden
Else
item.Visibility = Telerik.WinControls.ElementVisibility.Visible
End If
Next
End If
End Sub
Private Function IsExpandable(hierarchyRow As GridViewHierarchyRowInfo) As Boolean
For Each view As GridViewInfo In hierarchyRow.Views
If view.ChildRows.Count > 0 Then
Return True
End If
Next
Return False
End Function
Workaround:
AddHandler Me.RadGridView1.ChildViewExpanding, AddressOf RadGridView1_ChildViewExpanding
AddHandler Me.RadGridView1.MouseDown, AddressOf RadGridView_MouseDown
Private Sub RadGridView1_ChildViewExpanding(sender As Object, e As ChildViewExpandingEventArgs)
If lastClicked IsNot Nothing AndAlso e.ParentRow.Equals(lastClicked) Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub
Dim lastClicked As GridViewRowInfo
Private Sub RadGridView_MouseDown(sender As Object, e As MouseEventArgs)
Dim expander As GridExpanderItem = TryCast(Me.RadGridView1.ElementTree.GetElementAtPoint(e.Location), GridExpanderItem)
If expander IsNot Nothing Then
lastClicked = DirectCast(expander.Parent, GridGroupExpanderCellElement).RowInfo
End If
End Sub
To reproduce: add a RadGridView and a RadButton on the form. Use the following code snippet:
public RadForm1()
{
InitializeComponent();
this.radGridView1.Columns.Add("Col1");
this.radGridView1.Columns.Add("Col2");
for (int i = 0; i < 5; i++)
{
this.radGridView1.Rows.Add(i, "Item" + i);
}
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.RowValidating += radGridView1_RowValidating;
this.radGridView1.UserAddingRow += radGridView1_UserAddingRow;
}
private void radGridView1_UserAddingRow(object sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e)
{
e.Cancel = true;
}
private void radGridView1_RowValidating(object sender, Telerik.WinControls.UI.RowValidatingEventArgs e)
{
if (e.Row.IsModified && e.Row is GridViewDataRowInfo)
{
e.Cancel = true;
}
}
private void radButton1_Click(object sender, EventArgs e)
{
RadMessageBox.Show("Clicked");
}
1. Select a data cell and activate the editor. Enter some new value and click the button. The Click event is fired.
2. Select the new row and activate the editor. Enter some value and click the button. The Click event is NOT fired.
Workaround: use the CellValidating event instead.
To reproduce:
- Add several columns including combo-box columns to a grid.
- Add one row and upon a button click, change the data source of the combo column.
Workaround:
Seth the following field to null prior changing the data source:
GetType(GridViewComboBoxColumn).GetField("nullBoundItem", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).SetValue(combo, Nothing)
combo.DataSource = dt
To reproduce:
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
for (int i = 0; i < 1; i++)
{
dt.Rows.Add(i, "Item");
}
this.radGridView1.DataSource = dt;
this.radGridView1.SelectionMode = GridViewSelectionMode.FullRowSelect;
this.radGridView1.ClipboardCopyMode = Telerik.WinControls.UI.GridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
this.radGridView1.MultiSelect = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.radGridView1.SelectAll();
this.radGridView1.Copy();
}
If you click the button, you will notice that only one cell is copied. However, if you add 2 and more rows, the whole grid content will be copied to the clipboard.
Workaround: use the BeginRowCopy/EndRowCopy methods.
private void button1_Click(object sender, EventArgs e)
{
this.radGridView1.SelectAll();
this.radGridView1.MasterTemplate.BeginRowCopy();
this.radGridView1.Copy();
this.radGridView1.MasterTemplate.EndRowCopy();
}
How to reproduce:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn();
decimalColumn.Name = "DecimalColumn";
decimalColumn.HeaderText = "DecimalColumn";
this.radGridView1.MasterTemplate.Columns.Add(decimalColumn);
GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn();
textBoxColumn.Name = "TextBoxColumn";
textBoxColumn.HeaderText = "TextBoxColumn";
this.radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
GridViewDateTimeColumn dateTimeColumn = new GridViewDateTimeColumn();
dateTimeColumn.Name = "DateTimeColumn";
dateTimeColumn.HeaderText = "DateTimeColumn";
this.radGridView1.MasterTemplate.Columns.Add(dateTimeColumn);
}
}
Workaround: this.radGridView1.MasterView.TableAddNewRow.MinHeight = 30;
Steps to reproduce: 1. Add a CompositeFilterDescriptor programmatically as it is demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/filtering/setting-filters-programmatically-(composite-descriptors) 2. Save the layout. 3. Load the layout. Use attached project to reproduce. Workaround: Seth te PropertyName to a valid column name.
To reproduce:
this.Controls.Add(this.radGridView1);
this.radScheduler1.Dock = DockStyle.Fill;
List<GridRec> records = new List<GridRec>();
GridRec rec = new GridRec();
rec.Column1 = "1";
rec.Column2 = "2";
rec.Column3 = "3";
rec.Column4 = "4";
rec.Column5 = "5";
rec.Column6 = "6";
rec.Column7 = "7";
rec.Column8 = "8";
rec.Column9 = "9";
for (int i = 0; i < 20; ++i)
{
records.Add(rec.Clone());
}
radGridView1.DataSource = records;
this.radGridView1.MultiSelect = true;
this.radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
this.radGridView1.Dock = DockStyle.Fill;
public class GridRec
{
public GridRec Clone()
{
return this.MemberwiseClone() as GridRec;
}
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
public string Column4 { get; set; }
public string Column5 { get; set; }
public string Column6 { get; set; }
public string Column7 { get; set; }
public string Column8 { get; set; }
public string Column9 { get; set; }
}
If you run the application, it starts with the upper-left most cell selected. Now, while holding down the Shift key, left-click on the cell in the 5th column of the 5th row (cell 5:5). Note all 25 cells are selected as expected. Now, while still holding Shift, left-click again on cell 5:5 and note the selection is cleared.
Now, while still holding Shift, click on cell 4:4 (4th column, 4th row). Note how the selected range is now cells 1:1 through 4:4. And while still holding Shift, if you click on 4:4 yet again, the selection is cleared.
Workaround:
private void radGridView1_SelectionChanging(object sender, Telerik.WinControls.UI.GridViewSelectionCancelEventArgs e)
{
if (e.ColumnStartIndex == e.ColumnEndIndex && Control.ModifierKeys == Keys.Shift)
{
e.Cancel = true;
}
}
Please refer to the attached sample project and gif file illustrating the problem.
Workaround:
Sub New()
InitializeComponent()
AddHandler Me.RadGridView1.CreateCell, AddressOf RadGridView_CreateCell
End Sub
Public Class CustomGridFilterCellElement
Inherits GridFilterCellElement
Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
Get
Return GetType(GridFilterCellElement)
End Get
End Property
Public Sub New(column As GridViewDataColumn, row As GridRowElement)
MyBase.New(column, row)
End Sub
Protected Overrides Function ApplyFormatString(value As Object) As String
Return CDate(value).ToString("dd.MM.yyyy")
End Function
End Class
To reproduce:
- Add DateTime columns to the grid and set the MaskType of the editor to FreeFormDateTime.
- Go to the new row enter a valid date and press Tab.
Workaround:
class Myditor : RadDateTimeEditor
{
public override bool IsModified
{
get
{
return true;
}
}
}
To reproduce:
private void MasterTemplate_ViewChanged(object sender, DataViewChangedEventArgs args)
{
if (args.Action == ViewChangedAction.ExpandedChanged)
{
}
}
Workaround:
- Use the GroupExpanded event.
To reproduce: please refer to the attached sample project and gif file illustrating the behavior.
Workaround: in order to cancel adding of the new row, you can call the MasterView.TableAddNewRow.CancelAddNewRow method:
private void radGridView1_UserAddingRow(object sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e)
{
e.Cancel = true;
this.radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
int index = this.radGridView1.Rows.Count;
this.radGridView1.Rows.Add(index, "Row" + index);
}
To reproduce:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
DataTable dt = NewDt();
this.radGridView1.DataSource = dt;
var c = this.radGridView1.Columns["Calculted"] as GridViewDecimalColumn;
c.EnableExpressionEditor = true;
c.Expression = "Column2 / SUM(Column2) * 10";
c.DecimalPlaces = 2;
c.FormatString = "{0:N2}";
this.radGridView1.GroupDescriptors.Add("GroupByColumn", ListSortDirection.Ascending);
}
private DataTable NewDt()
{
var dt = new DataTable();
dt.Columns.Add("ItemColumn");
dt.Columns.Add("GroupByColumn");
dt.Columns.Add("Column2", typeof(decimal));
dt.Columns.Add("Calculted", typeof(decimal));
for (int i = 1; i <= 20; i++)
{
string gr = string.Empty;
if (i % 3 == 0)
gr = "gr3";
else if (i % 2 == 0)
gr = "gr2";
else if (i % 5 == 0)
gr = "gr5";
else
gr = "item" + i.ToString();
dt.Rows.Add("id #" + i.ToString(), gr, i, 0);
}
return dt;
}
Workaround:
public class CustomExpressionContext : Telerik.Data.Expressions.ExpressionContext
{
RadGridView radGridView;
public CustomExpressionContext(RadGridView grid)
{
this.radGridView = grid;
}
public decimal MySum(string columnName)
{
decimal sum = 0;
foreach (var item in radGridView.Rows)
{
sum += (decimal)item.Cells[columnName].Value;
}
return sum;
}
}
Telerik.Data.Expressions.ExpressionContext.Context = new CustomExpressionContext(this.radGridView1);
How to reproduce:
public partial class Form1 : Form
{
public class Data
{
public bool Checked { get; set; }
public string Text { get; set; }
}
private readonly RadGridView _grid;
private readonly List<Data> _dataList = new List<Data>
{
new Data {Text = "abc"},
new Data {Text = "def"},
new Data {Text = "ghi"},
new Data {Text = "jkl"},
new Data {Text = "mno"},
new Data {Text = "pqr"},
new Data {Text = "stu"},
new Data {Text = "vwx"},
new Data {Text = "yz0"}
};
public Form1()
{
InitializeComponent();
_grid = new RadGridView
{
Dock = DockStyle.Fill,
AllowSearchRow = true
};
Controls.Add(_grid);
_grid.DataSource = _dataList;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
((GridViewCheckBoxColumn)_grid.Columns["Checked"]).EnableHeaderCheckBox = true;
_grid.Columns["Checked"].SortOrder = RadSortOrder.Ascending;
((GridViewCheckBoxColumn)_grid.Columns["Checked"]).Checked = ToggleState.On;
_grid.MasterView.TableSearchRow.Search("abc");
}
}
Workaround: clear the search text
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
((GridViewCheckBoxColumn)_grid.Columns["Checked"]).EnableHeaderCheckBox = true;
_grid.Columns["Checked"].SortOrder = RadSortOrder.Ascending;
((GridViewCheckBoxColumn)_grid.Columns["Checked"]).Checked = ToggleState.On;
_grid.MasterView.TableSearchRow.Search("abc");
this._grid.MouseDown += _grid_MouseDown;
}
private void _grid_MouseDown(object sender, MouseEventArgs e)
{
RadGridView grid = (RadGridView)sender;
RadCheckBoxElement cell = grid.ElementTree.GetElementAtPoint(e.Location) as RadCheckBoxElement;
if (cell != null && cell.Parent is GridCheckBoxHeaderCellElement && grid.SortDescriptors.Count > 0))
{
grid.MasterView.TableSearchRow.Search("");
}
}
Please refer to the attached sample project and gif file illustrating the behavior.
ColumnGroupsViewDefinition view = this.radGridView1.ViewDefinition as ColumnGroupsViewDefinition;
foreach (GridViewColumnGroup group in view.ColumnGroups)
{
group.ShowHeader = false;
}
Workaround: use the ViewCellFormatting and enable the back color for the header cells that are over the hidden group headers
public RadForm1()
{
InitializeComponent();
ColumnGroupsViewDefinition view = this.radGridView1.ViewDefinition as ColumnGroupsViewDefinition ;
foreach (GridViewColumnGroup group in view.ColumnGroups)
{
group.ShowHeader = false;
}
}
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.Row is GridViewTableHeaderRowInfo && !(e.CellElement is GridColumnGroupCellElement))
{
e.CellElement.DrawFill = true;
e.CellElement.BackColor = Color.FromArgb(234, 242, 252);
e.CellElement.GradientStyle = GradientStyles.Solid;
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
}
}
To reproduce - Start the attached project press "Add in code" then "Save" - The row is still not added to the underlying data table. Workaround: TryCast(Me.radGridView1.Rows.Last().DataBoundItem, IEditableObject).EndEdit()