Workaround: Inherit the GridViewSearchRowInfo and override the SelectNextSearchResult method
class MyGridViewSearchRowInfo : GridViewSearchRowInfo
{
private GridViewInfo gridViewInfo;
private RadGridView radGridView;
public MyGridViewSearchRowInfo(GridViewInfo gridViewInfo, RadGridView radGridView)
: base(gridViewInfo)
{
this.radGridView = radGridView;
}
public override Type RowElementType {
get { return typeof(GridSearchRowElement); }
}
public override void SelectNextSearchResult()
{
if (this.radGridView != null) {
this.radGridView.ElementTree.Control.Invoke(() => { base.SelectNextSearchResult(); });
}
}
}
To reproduce:
- Add a grid to a split panel.
- Edit a cell and resize the panel without ending the edit.
- Click back in the same cell.
Workaround:
private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
BaseGridEditor editor = e.ActiveEditor as BaseGridEditor;
var element = editor.EditorElement as RadTextBoxEditorElement;
if (element != null)
{
element.TextBoxItem.HostedControl.LostFocus -= HostedControl_LostFocus;
element.TextBoxItem.HostedControl.LostFocus += HostedControl_LostFocus;
}
}
private void HostedControl_LostFocus(object sender, EventArgs e)
{
this.RadGridView1.EndEdit();
}
Please refer to the attached sample project and follow the steps illustrated on the attached gif file.
Workaround: subscribe to the CellBeginEdit event and focus the grid:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.radGridView1.CellBeginEdit += radGridView1_CellBeginEdit;
}
private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
this.radGridView1.Focus();
}
}
To reproduce:
void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.Value == null || e.Value == DBNull.Value)
{
e.Row.Delete();
}
}
- Use the enter key to confirm the change
Workaround:
void radGridView1_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.Value == null || e.Value == DBNull.Value)
{
e.Row.Delete();
}
}
To reproduce:
- Add a ColumnGroupsViewDefinition
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
VisualStudio2012LightTheme theme = new VisualStudio2012LightTheme();
Telerik.WinControls.ThemeResolutionService.ApplicationThemeName = theme.ThemeName;
this.radGridView1.BestFitColumns();
}
Workaround:
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
this.radGridView1.BestFitColumns();
VisualStudio2012LightTheme theme = new VisualStudio2012LightTheme();
Telerik.WinControls.ThemeResolutionService.ApplicationThemeName = theme.ThemeName;
}
To reproduce: - Set the row height to 1000. - Call the grid PrintPreview method. As workaround one can set the MaxHeight of the rows prior printing.
To reproduce:
- Bind the grid to a list of the following objects:
public class Test
{
private Status _Status = Status.Value1;
public Status Status
{
get { return _Status; }
set { _Status = value; }
}
private string _Name = "";
public string Name
{
get { return _Name; }
set { _Name = value; }
}
}
public enum Status
{
Value1,
Value2,
Value3
}
- Group Name column.
- Open at least one group.
- Close grouping.
- Group status column.
- Try to open status group.
Workaround:
GridViewComboBoxColumn col = radGridView1.Columns[0] as GridViewComboBoxColumn;
col.DisplayMemberSort = true;
Workaround: instead of using the default alternating row color for the mentioned themes, use the override theme setting in the CellFormatting event: http://www.telerik.com/help/winforms/tpf-override-theme-settings-at-run-time.html
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.Row is GridViewDataRowInfo)
{
if (e.RowIndex % 2 == 0)
{
e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red, "");
e.CellElement.SetThemeValueOverride(LightVisualElement.DrawFillProperty, true, "");
e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "");
}
else
{
e.CellElement.ResetThemeValueOverride(LightVisualElement.BackColorProperty, "");
e.CellElement.ResetThemeValueOverride(LightVisualElement.DrawFillProperty, "");
e.CellElement.ResetThemeValueOverride(LightVisualElement.GradientStyleProperty, "");
}
}
}
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.
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);
}
}
To reproduce: - Use RowFormatting to change the font style to bold. - Call the BestFitColumns method.
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:
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;
}
}
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:
- Sort the grid and then reset the data source.
- Format the rows like this:
void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
string exception_status = "";
string completed_user = "";
if (!DBNull.Value.Equals(e.RowElement.RowInfo.Cells["Name"].Value))
{
exception_status = e.RowElement.RowInfo.Cells["Name"].Value.ToString();
}
if (!DBNull.Value.Equals(e.RowElement.RowInfo.Cells["Drug"].Value))
{
completed_user = e.RowElement.RowInfo.Cells["Drug"].Value.ToString().Trim();
}
if (exception_status == "Sam" && completed_user == "Enebrel")
{
e.RowElement.ForeColor = Color.Red;
}
else
{
e.RowElement.ForeColor = Color.Black;
}
}
Workaround:
if (e.RowElement.RowInfo.Cells.Count ==0)
{
return;
}
To reproduce:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.RadGridView1.DataSource = Me.ProductsBindingSource
Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
Dim obj As New ConditionalFormattingObject("MyCondition", ConditionTypes.Greater, "30", "", False)
obj.CellBackColor = Color.SkyBlue
obj.CellForeColor = Color.Red
obj.TextAlignment = ContentAlignment.MiddleRight
Me.RadGridView1.Columns("UnitPrice").ConditionalFormattingObjectList.Add(obj)
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim mySQL As String = "SELECT * FROM Products where ProductName = 'Chaii'"
Dim myTable As DataTable = getDataInTable(mySQL, My.Settings.NwindConnectionString)
Me.RadGridView1.DataSource = myTable
End Sub
Public Shared Function getDataInTable(mySQLorTable As String, myConnectionString As String, Optional myTimeout As Integer = 30) As DataTable
Using myConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Nwind.mdb")
Dim myCommand As New OleDb.OleDbCommand(mySQLorTable, myConnection)
myConnection.Open()
Dim myDataTable As New DataTable
Dim myAdapter As New OleDb.OleDbDataAdapter(myCommand)
myAdapter.Fill(myDataTable)
Return myDataTable
End Using
End Function
When you click the button, the grid is refilled with the query result which does not contain any rows. As a result, a DataException is thrown for each column: "There is no property descriptor corresponding to property name: 'ColumnName'" .
Workaround: clear the conditional formatting objects, reset the DataSource and add the conditional formatting objects back
To reproduce:
Add the following view:
for (int i = 0; i < 8; i++)
{
radGridView2.Columns.Add("Col" + (i+1));
}
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
view.ColumnGroups.Add(new GridViewColumnGroup("G1"));
view.ColumnGroups.Add(new GridViewColumnGroup("G2"));
view.ColumnGroups.Add(new GridViewColumnGroup("G3"));
view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].ColumnNames.Add("Col1");
view.ColumnGroups[0].Rows[0].ColumnNames.Add("Col2");
view.ColumnGroups[0].Rows[0].ColumnNames.Add("Col3");
view.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[1].Rows[0].ColumnNames.Add("Col4");
view.ColumnGroups[1].Rows[0].ColumnNames.Add("Col5");
view.ColumnGroups[2].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[2].Rows[0].ColumnNames.Add("Col6");
view.ColumnGroups[2].Rows[0].ColumnNames.Add("Col7");
view.ColumnGroups[2].Rows[0].ColumnNames.Add("Col8");
radGridView2.ViewDefinition = view;
for (int i = 0; i < 10; i++)
{
radGridView2.Rows.Add("row"+i, "test","test","test","test","test","test");
}
radGridView2.Columns[2].IsVisible = false;
radGridView2.Columns[7].IsVisible = false;
- Then export the grid with the spread exporter.
To reproduce:
- Create load on demand hierarchy.
- Open the excel filter popup.
- The RowSourceNeeded event fires for all rows.
Workaround:
public class MyGridHeaderCellElement : GridHeaderCellElement
{
public MyGridHeaderCellElement(GridViewDataColumn col, GridRowElement row) : base(col, row)
{
}
protected override Type ThemeEffectiveType
{
get { return typeof(GridHeaderCellElement); }
}
protected override IGridFilterPopup CreateFilterPopup()
{
this.GridControl.Tag = "FileterInitializing";
return base.CreateFilterPopup();
}
}
// in the main forms you cab skip the event code execution while the popup is initialized
private void RadGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
this.radGridView1.Tag = null;
}
private void RadGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (object.ReferenceEquals(e.CellType, typeof(GridHeaderCellElement)))
{
e.CellType = typeof(MyGridHeaderCellElement);
}
}
void radGridView1_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{
if (radGridView1.Tag != null && radGridView1.Tag == "FileterInitializing")
{
return;
}
//other code
}
To reproduce:
- Add some columns to the grid, make sure that most of the columns are not visible (the user must scroll to view them).
- Drag and drop the second column at the last position in the grid.
- The result can be seen on the attached image.
Workaround:
Private Sub Columns_CollectionChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs)
Me.RadGridView1.TableElement.ViewElement.UpdateRowsWhenColumnsChanged()
End Sub
To reproduce: - Add an expression column with nullable type as a data source. - Open the property builder. Workaround: Set the data type at run time.