Similar property is already available in the property grid and tree view exporters.
To reproduce:
BindingList<Item> items = new BindingList<Item>();
public Form1()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
items.Add(new Item(i,i * 1.25m));
}
this.radGridView1.DataSource = items;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Price";
summaryItem.Aggregate = GridAggregateFunction.Sum;
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
this.radGridView1.SummaryRowsTop.Add(summaryRowItem);
this.timer1.Start();
}
public class Item
{
private int id;
private decimal price;
public Item(int id, decimal price)
{
this.id = id;
this.price = price;
}
public int Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
public decimal Price
{
get
{
return this.price;
}
set
{
this.price = value;
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
items[0].Price += 1;
this.radGridView1.Rows[0].InvalidateRow();
this.radGridView1.MasterView.SummaryRows[0].InvalidateRow();
}
Workaround: refresh the MasterTemplate or implement the INotifyPropertyChanged
Work around: create a custom GridCheckBoxHeaderCellElement and override the SetCheckBoxState method
public class MyGridCheckBoxHeaderCellElement : GridCheckBoxHeaderCellElement
{
public MyGridCheckBoxHeaderCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override Type ThemeEffectiveType
{
get { return typeof(GridHeaderCellElement); }
}
protected override bool SetCheckBoxState()
{
bool foundNonCheckedRows = false;
foreach (GridViewRowInfo row in this.ViewInfo.Rows)
{
foundNonCheckedRows = this.CheckCheckBoxValueForAllRows(row, foundNonCheckedRows);
if (foundNonCheckedRows)
{
SetCheckBoxState(ToggleState.Off);
break;
}
}
if (!foundNonCheckedRows && this.ViewInfo.Rows.Count > 0) //we must have at least one row in order to check the header cell
{
SetCheckBoxState(ToggleState.On);
}
return foundNonCheckedRows;
}
private bool CheckCheckBoxValueForAllRows(GridViewRowInfo row, bool foundNonCheckedRows)
{
GridViewChildRowCollection currentRowColection;
if (foundNonCheckedRows)
{
return foundNonCheckedRows;
}
if (row.HasChildRows())
{
currentRowColection = row.ChildRows;
}
else
{
currentRowColection = row.ViewInfo.Rows;
}
foreach (GridViewRowInfo rowInfo in currentRowColection)
{
GridViewGroupRowInfo groupInfo = rowInfo as GridViewGroupRowInfo;
if (groupInfo != null)
{
foundNonCheckedRows = this.CheckCheckBoxValueForAllRows(groupInfo, foundNonCheckedRows);
}
else
{
object cellValue = rowInfo.Cells[this.ColumnIndex].Value;
bool? valueFromColumnTypeConvertor = null;
if (this.ColumnInfo is GridViewDataColumn)
{
TypeConverter convertor = ((GridViewDataColumn)this.ColumnInfo).DataTypeConverter;
if (convertor != null && (convertor.CanConvertTo(typeof(bool)) || convertor.CanConvertTo(typeof(ToggleState))))
{
try
{
valueFromColumnTypeConvertor = Convert.ToBoolean(convertor.ConvertTo(cellValue, typeof(bool)));
}
catch (FormatException)//convert to bool fails
{
}
catch (NotSupportedException)//coverting NULL
{
}
}
}
try
{
if (rowInfo != this.RowInfo &&
(cellValue == null || cellValue == DBNull.Value) ||
(valueFromColumnTypeConvertor.HasValue && !valueFromColumnTypeConvertor.Value) ||
(!valueFromColumnTypeConvertor.HasValue && !Convert.ToBoolean(cellValue)))
{
foundNonCheckedRows = true;
}
}
catch (FormatException)//convert to bool fails
{
}
}
}
return foundNonCheckedRows;
}
}
To reproduce: - Add 100000 rows to the grid. - Filter the grid so there are no rows. - Call the BestFitColumns method: radGridView1.MasterTemplate.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.DisplayedCells) Workaround: If gridview.MasterTemplate.DataView.Count > 0 Then gridview.MasterTemplate.BestFitColumns() End If
To reproduce:
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
for (int i = 0; i < 10; i++)
{
dt.Columns.Add("Col" + i);
}
for (int i = 0; i < 10; i++)
{
DataRow row = dt.NewRow();
foreach (DataColumn col in dt.Columns)
{
row[col.ColumnName] = "Data " + i + "." + dt.Columns.IndexOf(col);
}
dt.Rows.Add(row);
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom;
this.radGridView1.Columns[9].IsVisible = false;
this.radGridView1.Columns[8].ReadOnly = true;
this.radGridView1.Columns[2].IsVisible = false;
this.radGridView1.Columns[4].IsVisible = false;
this.radGridView1.Columns[6].IsVisible = false;
}
Workaround: use a custom row behavior and control what to be the selected cell when pressing the Tab key for example:
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
for (int i = 0; i < 10; i++)
{
dt.Columns.Add("Col" + i);
}
for (int i = 0; i < 10; i++)
{
DataRow row = dt.NewRow();
foreach (DataColumn col in dt.Columns)
{
row[col.ColumnName] = "Data " + i + "." + dt.Columns.IndexOf(col);
}
dt.Rows.Add(row);
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom;
this.radGridView1.Columns[9].IsVisible = false;
this.radGridView1.Columns[8].ReadOnly = true;
this.radGridView1.Columns[2].IsVisible = false;
this.radGridView1.Columns[4].IsVisible = false;
this.radGridView1.Columns[6].IsVisible = false;
//register the custom row behavior
BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewNewRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewNewRowInfo), new CustomGridHierarchyRowBehavior());
}
public class CustomGridHierarchyRowBehavior : GridNewRowBehavior
{
protected override bool ProcessTabKey(KeyEventArgs keys)
{
bool isLastColumn = this.Navigator.IsLastColumn(this.GridControl.CurrentColumn);
bool result = base.ProcessTabKey(keys);
if (isLastColumn)
{
this.GridControl.CurrentColumn = this.GridControl.Columns[0];
this.GridControl.BeginEdit();
}
return result;
}
}
To reproduce:
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact"));
view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].ColumnNames.Add("Address");
view.ColumnGroups[0].Rows[0].ColumnNames.Add("Contact");
radGridView1.Columns.Add("Address");
radGridView1.Columns.Add("Contact");
radGridView1.Columns[0].Width = 300;
radGridView1.Columns[1].Width = 300;
radGridView1.ViewDefinition = view;
for (int i = 0; i < 10; i++)
{
radGridView1.Rows.Add("test test test test test", "test");
}
Workaround:
docs.telerik.com/devtools/winforms/telerik-presentation-framework/export-renderers/spreadexportrenderer
To reproduce:
- Add date time column to a grid and set the MaskType to FreeFormDateTime (this can be done by accessing the editor in the CellEditorInitialized event).
- Type a year in the editor and click the right arrow key until the cell is changed.
Workaround:
class MyRadDateTimeEditor : RadDateTimeEditor
{
bool isRightmostMaskItemSelected = false;
public override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
FreeFormDateTimeProvider provider = ((RadDateTimeEditorElement) this.EditorElement).TextBoxElement.Provider as FreeFormDateTimeProvider;
if (provider.TextBoxItem.SelectionStart == provider.TextBoxItem.Text.Length)
{
this.isRightmostMaskItemSelected = true;
}
}
else
{
base.OnKeyDown(e);
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
if (isRightmostMaskItemSelected)
{
isRightmostMaskItemSelected = false;
GridDateTimeCellElement cell = this.OwnerElement as GridDateTimeCellElement;
cell.GridControl.EndEdit();
}
}
else
{
base.OnKeyUp(e);
}
}
}
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor != null)
{
var editorElement = editor.EditorElement as RadDateTimeEditorElement;
editorElement.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
}
}
Please find attached a sample project. 1. Select the new row and activate te editor. 2. Do not enter any value and click outside the new row. The exception is thrown. Workaround: bind directly to the query result: this.radGridView1.DataSource = (from p in context.Customers select p).ToList();
To reproduce: -Create a new ColumnGroupsViewDefinition and pin the first group. - Asign the view to the grid. Workaround: Pin the group after the view is asigned.
To reproduce: use the attached sample project Workaround: refresh the template when updating the data source: this.radGridView1.MasterTemplate.Refresh();
To reproduce: - Use RowFormatting to change the font style to bold. - Call the BestFitColumns method.
To reproduce: - Add a grid with some columns at design time. - Open the designer code and you will notice the TableViewDefinition. Workaround: Manually delete the TableViewDefinition.
To reproduce:
Sub New()
InitializeComponent()
Dim items As New List(Of WorkOrder)
For index = 1 To 56
items.Add(New WorkOrder(index, "Item" & index, 0))
Next
Dim rand As New Random
For index = 57 To 500
items.Add(New WorkOrder(index, "Item" & index, rand.Next(1, 56)))
Next
Me.RadGridView1.Relations.AddSelfReference(Me.RadGridView1.MasterTemplate, "Id", "ParentId")
Me.RadGridView1.DataSource = items
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Me.RadGridView1.EnablePaging = True
Me.RadGridView1.PageSize = 20
End Sub
Public Class WorkOrder
Private _id As Integer
Private _name As String
Private _parentId As Integer
Public Sub New(id As Integer, name As String, parentId As Integer)
Me._id = id
Me._name = name
Me._parentId = parentId
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
Public Property ParentID() As Integer
Get
Return _parentId
End Get
Set(ByVal value As Integer)
_parentId = value
End Set
End Property
End Class
Workaround: use standard hierarchy: http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
Note: as a result ArgumentException is thrown when accessing a cell value.
To reproduce:
private DataTable dt;
private GridViewRowInfo selectedRow;
public Form1()
{
InitializeComponent();
PopulateGrid();
PopulateGrid();
}
private void PopulateGrid()
{
dt = new DataTable();
dt.Columns.Add("Version No", typeof(Int32));
DataRow dr = dt.NewRow();
dr["Version No"] = 2385;
dt.Rows.Add(dr);
this.radGridView1.DataSource = dt;
MessageBox.Show(selectedRow.Cells[0].ColumnInfo.Name);
MessageBox.Show(selectedRow.Cells[0].Value.ToString()); //This will error on the second time through
}
private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
//This event is not firing on the second population of the grid in the new Telerik version.
//In the old version, it did
if (!this.radGridView1.CurrentRow.IsSystem && !this.radGridView1.CurrentRow.HasChildRows() && this.radGridView1.CurrentRow.Cells.Count > 0)
selectedRow = this.radGridView1.CurrentRow;
}
Workaround: use the RadGridView.CurrentRow property directly when accessing the cell value.
To reproduce: - Add some columns to a grid and make one read-only. - Add a value to the new row then click the read-only cell. - Click outside of the grid (focus another control). - The new row is not added. Workaround: radgridView1.EndEdit() radgridView1.MasterView.TableAddNewRow.EndAddNewRow()
Please refer to the attached sample project.
Workaround:
public class MyGridCheckBoxCellElement : GridCheckBoxCellElement
{
public MyGridCheckBoxCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
{
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridCheckBoxCellElement);
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
GridViewCheckBoxColumn col = data as GridViewCheckBoxColumn;
if (col != null)
{
return col.ThreeState == ((RadCheckBoxEditor)this.Editor).ThreeState;
}
return base.IsCompatible(data, context);
}
}
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridCheckBoxCellElement))
{
e.CellElement = new MyGridCheckBoxCellElement(e.Column, e.Row);
}
}
Use the attached sample project. Workaround: hide the columns programmatically at run time.
Please refer to the attached gif file. Workaround: specify the MinimumSize property of the grid and its parent container to have a greater width than the DesiredSize of the group panel.