To reproduce:
- Add grid with a DateTime column with default value "5/1/2014";
- Start the app and press the following keys one after another: 5/1/
- You will notice that the "1" is not replaced.
Please note that the similar behavior occur when the year is entered (it does not match the default one).
Workaround handle the key press for such cases manually:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDateTimeEditor ed = e.ActiveEditor as RadDateTimeEditor;
RadDateTimeEditorElement el = ed.EditorElement as RadDateTimeEditorElement;
el.KeyPress += el_KeyPress;
}
private void el_KeyPress(object sender, KeyPressEventArgs e)
{
RadDateTimeEditorElement el = (RadDateTimeEditorElement)sender;
int day = el.Value.Value.Day;
int key = -1;
int.TryParse(e.KeyChar.ToString(), key);
RadMaskedEditBoxElement element = el.TextBoxElement.TextBoxItem.Parent as RadMaskedEditBoxElement;
MaskDateTimeProvider provider = element.Provider as MaskDateTimeProvider;
if (provider.SelectedItemIndex == 2) {
if (key > 0 & key <= 9) {
if (el.TextBoxElement.TextBoxItem.SelectionLength != 0) {
if (!booKeying) {
dynamic NewValue = new DateTime(el.Value.Value.Year, el.Value.Value.Month, key);
el.Value = NewValue;
e.Handled = true;
booKeying = true;
}
}
}
}
}
To reproduce:
- Filer twice by a single column with Excel-like filtering.
- The second time InvalidCastException will occur.
Workaround:
- Create custom columns and override the GetDistinctValues method.
public class MyColumn : GridViewTextBoxColumn
{
protected override GridViewColumnValuesCollection GetDistinctValues()
{
int index = this.Index;
if (index >= 0)
{
GridViewColumnValuesCollection distinctValues = new GridViewColumnValuesCollection();
foreach (GridViewRowInfo row in this.OwnerTemplate.Rows)
{
object cellValue = row.Cells[index].Value;
if (!distinctValues.Contains(cellValue))
{
distinctValues.Add(cellValue);
}
}
if (distinctValues.Count > 0)
{
return distinctValues;
}
}
return null;
}
}
Workaround: the MasterTemplate has Copy method, which allows overriding in its descendants. Thus, it is possible to modify the copied data according to the specific requirements:
public class CustomGrid : RadGridView
{
protected override RadGridViewElement CreateGridViewElement()
{
return new CustomRadGridViewElement();
}
public override string ThemeClassName
{
get
{
return typeof(RadGridView).FullName;
}
}
}
public class CustomRadGridViewElement : RadGridViewElement
{
protected override MasterGridViewTemplate CreateTemplate()
{
return new CustomMasterGridViewTemplate();
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadGridViewElement);
}
}
}
public class CustomMasterGridViewTemplate : MasterGridViewTemplate
{
public override void Copy()
{
base.Copy();
if (Clipboard.ContainsData(DataFormats.Text))
{
string data = Clipboard.GetData(DataFormats.Text).ToString();
if (data != string.Empty)
{
StringBuilder sb = new StringBuilder(data);
//modify the copied data and replace it in the clipboard
Clipboard.SetData(DataFormats.Text, sb.ToString());
}
}
}
}
To reproduce:
Create a self reference RadGridView and add enough columns so that a horizontal scrollbar appears. Scroll the horizontal scrollbar to the right and close the form. You will see an exception.
Workaround:
Create a custom row element in the CreateRow event:
void radGridView1_CreateRow(object sender, Telerik.WinControls.UI.GridViewCreateRowEventArgs e)
{
if (e.RowInfo is GridViewHierarchyRowInfo || e.RowInfo is GridViewDataRowInfo)
{
e.RowElement = new MyDataRowElement();
}
}
public class MyLayout : SelfReferenceCellLayout
{
public MyLayout(GridRowElement rowElement) : base(rowElement) { }
public override void DetachCellElements()
{
if (this.StackLayoutElement != null)
{
base.DetachCellElements();
}
}
}
public class MyDataRowElement : GridDataRowElement
{
private MyLayout cellReferenceLayout;
public override void Detach()
{
base.Detach();
if (this.cellReferenceLayout != null)
{
this.cellReferenceLayout.DetachCellElements();
}
}
protected override void DisposeManagedResources()
{
if (this.cellReferenceLayout != null)
{
this.cellReferenceLayout.Dispose();
}
base.DisposeManagedResources();
}
public override SelfReferenceCellLayout SelfReferenceLayout
{
get
{
if (this.RowInfo is GridViewHierarchyRowInfo)
{
if (this.ViewTemplate != null &&
this.ViewTemplate.IsSelfReference &&
this.cellReferenceLayout == null)
{
this.cellReferenceLayout = new MyLayout(this);
}
return this.cellReferenceLayout;
}
return null;
}
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataRowElement);
}
}
}
To reproduce:
Private _createDataTable As Object
Private _BoxValue As String
Sub New()
InitializeComponent()
RelCalculateValues()
Me.RadGridView1.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.AllCells)
End Sub
Private Sub RadGridView1_CellEndEdit(sender As Object, e As GridViewCellEventArgs) _
Handles RadGridView1.CellEndEdit
If e.RowIndex < 0 OrElse e.ColumnIndex < 0 Then Exit Sub
If e.Value = _BoxValue Then Exit Sub
If e.Column.Name <> "AllowedWane" Then Exit Sub
Dim fTester As Decimal
Dim rRow As Telerik.WinControls.UI.GridViewDataRowInfo = e.Row
Dim iRowID As Int32
iRowID = rRow.Cells("ID").Value
If iRowID < 0 Then Exit Sub
Select Case e.Column.Name
Case "AllowedWane"
If Decimal.TryParse(e.Value, fTester) = False Then
rRow.Cells(e.Column.Name).Value = _BoxValue
Exit Sub
Else
Select Case e.Column.OwnerTemplate.MasterTemplate.Owner.Name
Case RadGridView1.Name
RelCalculateValues(Me.RadGridView1)
End Select
End If
End Select
End Sub
Private Sub RelCalculateValues(ByVal rgvAsete As Telerik.WinControls.UI.RadGridView)
Dim dtJakauma As New DataTable
Dim drJakauma As DataRow
dtJakauma.Columns.Add("ID", GetType(Int32))
dtJakauma.Columns.Add("Dimensions", GetType(String))
dtJakauma.Columns.Add("Pcs", GetType(String))
dtJakauma.Columns.Add("Percents", GetType(String))
dtJakauma.Columns.Add("Price", GetType(String))
dtJakauma.Columns.Add("UsageFactor", GetType(String))
dtJakauma.Columns.Add("CubicMeters", GetType(String))
dtJakauma.Columns.Add("EdgeLimit", GetType(String))
dtJakauma.Columns.Add("AllowedWane", GetType(String))
dtJakauma.Columns.Add("Length", GetType(String))
For i As Int32 = 0 To 5
drJakauma = dtJakauma.NewRow
drJakauma("ID") = 0
drJakauma("Dimensions") = "Dimensions_" & i
drJakauma("Pcs") = "Pcs_" & i
drJakauma("Percents") = "Percents_" & i
drJakauma("Price") = "Price_" & i
drJakauma("UsageFactor") = "UsageFactor_" & i
drJakauma("CubicMeters") = "CubicMeters_" & i
drJakauma("EdgeLimit") = "EdgeLimit_" & i
drJakauma("AllowedWane") = "AllowedWane_" & i
drJakauma("Length") = "Length_" & i
dtJakauma.Rows.Add(drJakauma)
Next
rgvAsete.DataSource = dtJakauma
rgvAsete.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.AllCells)
End Sub
Workaround: set the RadGridView.DataSource to null/Nothing before setting it to the new DataTable.
Note: it is reproducible when using ColumnGroupsViewDefinition too. Workaround: unpin all pinned columns before printing and restore their state after printing:
To reproduce:
public Form1()
{
InitializeComponent();
radGridView1.ToolTipTextNeeded += radGridView1_ToolTipTextNeeded;
}
private void radGridView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
{
GridDataCellElement cell = sender as GridDataCellElement;
if (cell != null)
{
e.ToolTipText = cell.Value.ToString();
toolTipText = e.ToolTipText;
e.ToolTip.OwnerDraw = true;
e.ToolTip.Draw += ToolTip_Draw;
e.ToolTip.Popup += ToolTip_Popup;
}
}
private void ToolTip_Popup(object sender, PopupEventArgs e)
{
e.ToolTipSize = TextRenderer.MeasureText(toolTipText + " ", newFont);
}
Font newFont = new Font("Arial", 15f, FontStyle.Bold);
string toolTipText = string.Empty;
private void ToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);
e.DrawBorder();
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Far;
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
sf.FormatFlags = StringFormatFlags.NoClip;
e.Graphics.DrawString(e.ToolTipText, newFont, Brushes.Red, e.Bounds, sf);
}
}
RadGridView, TextBoxColumn - add support for autocomplete.
To reproduce: Add a RadGridView with some data and enable the paging functionality. Also set the AutoSize property to true: grid.EnablePaging = true; grid.AutoSize = true; Start the application and you will see that when you try to edit the textbox with the number of the page you will not be able to. Workaround: Set the AutoSize property to false and use MinimumSize instead: grid.AutoSize = false; grid.MinimumSize = new Size(600, 500);
To reproduce:
Use the code snippet below:
static DataSet ds;
public form1()
{
InitializeComponent();
GridviewStyling(radGridView1);
ds = PrepareDataset();
BuildGrid();
//Set_Hierarchy();
for (int i = 0; i < radGridView1.Templates.Count; i++)
GridviewTemplateStyling(radGridView1.Templates[i]);
this.radGridView1.TableElement.PageViewMode = PageViewMode.ExplorerBar;
this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
}
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
GridDetailViewCellElement detailCell = e.CellElement as GridDetailViewCellElement;
if (detailCell != null)
{
GridViewHierarchyRowInfo hierarchyRow = (GridViewHierarchyRowInfo)((GridViewDetailsRowInfo)detailCell.RowInfo).Owner;
detailCell.PageViewElement.Header.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
RadPageViewElement el = detailCell.PageViewElement as RadPageViewExplorerBarElement;
if (el != null)
{
for (int i = 0; i < el.Items.Count; i++) // detailCell.PageViewElement.Items.Count
{
RadPageViewItem item = detailCell.PageViewElement.Items[i];
GridViewInfo viewInfo = hierarchyRow.Views[i];
item.MaxSize = new Size(0, 1);
item.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
if (viewInfo.ChildRows.Count != 0)
{
item.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
}
}
}
}
private DataSet PrepareDataset()
{
Random r = new Random();
DataSet ds = new DataSet("DS");
//snir
DataTable dtFirst = new DataTable("Snir");
dtFirst.Columns.Add("pId", typeof(int));
dtFirst.Columns.Add("Col1", typeof(int));
dtFirst.Columns.Add("Col", typeof(string));
dtFirst.Columns.Add("Col3", typeof(int));
dtFirst.Columns.Add("Col4", typeof(string));
for (int i = 0; i < 5; i++)
dtFirst.Rows.Add(1, i, "snirsnirsnir" + r.Next(0, 100).ToString(),
r.Next(0, 35), "snir" + r.Next(0, 100).ToString());
// jenny
DataTable dtSecond = new DataTable("Jenny");
dtSecond.Columns.Add("pId", typeof(int));
dtSecond.Columns.Add("Col1", typeof(int));
dtSecond.Columns.Add("Col2", typeof(string));
dtSecond.Columns.Add("Col3", typeof(int));
dtSecond.Columns.Add("Col4", typeof(string));
dtSecond.Columns.Add("Col5", typeof(string));
dtSecond.Columns.Add("Col6", typeof(string));
for (int i = 0; i < 5; i++)
dtSecond.Rows.Add(2, i, "CnC" + r.Next(0, 100).ToString(),
r.Next(0, 35), "jenny" + r.Next(0, 100).ToString(), "col5", "col6");
//index
DataTable table1 = new DataTable("Index");
table1.Columns.Add("TableId", typeof(int));
table1.Columns.Add("TableName", typeof(string));
table1.Columns.Add("UpdateType", typeof(int));
table1.Rows.Add(1, dtFirst.TableName, r.Next(0, 3));
table1.Rows.Add(2, dtSecond.TableName, r.Next(0, 3));
ds.Tables.AddRange(new DataTable[] { table1, dtFirst, dtSecond });
return ds;
}
private void BuildGrid()
{
// bind the master template
this.radGridView1.DataSource = ds;
this.radGridView1.DataMember = "Index";
//templates
GridViewTemplate template1 = new GridViewTemplate();
template1.DataSource = ds.Tables[1];
template1.Columns[0].IsVisible = false;
template1.EnableHierarchyFiltering = false;
template1.ShowGroupedColumns = false;
radGridView1.Templates.Add(template1);
GridViewTemplate template2 = new GridViewTemplate();
template2.DataSource = ds.Tables[2]; // 1:snir // 2:jenny
radGridView1.Templates.Add(template2);
template1.AllowDragToGroup = false;
//relations
GridViewRelation relation1 = new GridViewRelation(radGridView1.MasterTemplate);//, template2);
relation1.RelationName = "myRelation1";
relation1.ChildTemplate = radGridView1.Templates[0];
relation1.ChildColumnNames.AddRange(new string[] { "pId" });
relation1.ParentColumnNames.Add("TableId");
radGridView1.Relations.Add(relation1);
GridViewRelation relation2 = new GridViewRelation(radGridView1.MasterTemplate);//, template2);
relation2.RelationName = "myRelation2";
relation2.ChildTemplate = radGridView1.Templates[1];
relation2.ChildColumnNames.AddRange(new string[] { "pId" });
relation2.ParentColumnNames.Add("TableId");
radGridView1.Relations.Add(relation2);
}
private void GridviewStyling(RadGridView rgv)
{
//radGridView1 styling
rgv.AllowAddNewRow = false;
rgv.EnableGrouping = false;
rgv.AllowDragToGroup = false;
rgv.AllowDrop = false;
rgv.AllowEditRow = false;
rgv.AllowDrop = false;
rgv.AllowRowResize = false;
rgv.AllowColumnResize = false;
rgv.AutoExpandGroups = true;
rgv.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
rgv.EnableCustomGrouping = false;
rgv.ShowColumnHeaders = true;
rgv.ShowRowHeaderColumn = false;
rgv.ShowGroupPanel = false;
}
private void GridviewTemplateStyling(GridViewTemplate gvt)
{
//template styling
gvt.AllowAddNewRow = false;
gvt.Columns[0].IsVisible = false;
gvt.ShowChildViewCaptions = false;
gvt.AllowDragToGroup = false;
gvt.AllowRowResize = false;
gvt.AllowColumnResize = false;
gvt.AutoExpandGroups = true;
gvt.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
gvt.ShowRowHeaderColumn = false;
gvt.ShowColumnHeaders = true;
}
private string GetEnumString(int n)
{
switch (n)
{
case (int)TableUpdateModeEnum.INSERT:
return "INSERT";
case (int)TableUpdateModeEnum.UPDATE:
return "UPDATE";
case (int)TableUpdateModeEnum.UPDATE_OR_INSERT:
return "UPDATE/DELETE";
case (int)TableUpdateModeEnum.DELETE_OR_INSERT:
return "INSERT/DELETE";
default:
return "";
}
}
public enum TableUpdateModeEnum
{
[Description("Snir")]
INSERT = 0,
[Description("Liraz")]
UPDATE_OR_INSERT = 1,
[Description("Jenny")]
UPDATE = 2,
[Description("Tsuria")]
DELETE_OR_INSERT = 3
};
Scenario:
1.Expand a master row.
2.Start dragging columns from the child template.
3.When your are dragging over the thick border , the exception occur.
Resolution: Please use the following code snippet to replace RadGridViewDragDropService: this.radGridView1.GridViewElement.RegisterService(new CustomDragDropService(this.radGridView1.GridViewElement));
If one sets AutoSizeRows to true and AllowSearchRow to true the layout of RadGridView throws an exception.
To reproduce:
1.Add a RadGridView and add twelve columns at design time.
2.Enable filtering and use the following code:
public Form1()
{
InitializeComponent();
radGridView1.MasterTemplate.MultiSelect = true;
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var column in radGridView1.Columns)
{
column.Width = 100;
}
}
3.When you run the application, click over the filtering cell for the 3rd column. Type in some text and click the filter button. As a result the horizontal scroll bar is positioned at right most.
Workaround:
radGridView1.MouseDown += radGridView1_MouseDown;
radGridView1.TableElement.HScrollBar.ValueChanged += HScrollBar_ValueChanged;
int scrollBarValue = 0;
bool shouldResetValue = false;
private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
RadElement clickecElement = this.radGridView1.ElementTree.GetElementAtPoint(e.Location);
GridFilterRowElement filterRowElement = clickecElement.FindAncestor<GridFilterRowElement>();
GridNewRowElement newRowElement = clickecElement.FindAncestor<GridNewRowElement>();
if (clickecElement is GridFilterRowElement || clickecElement is GridNewRowElement ||
filterRowElement != null || newRowElement != null)
{
shouldResetValue = true;
}
else
{
shouldResetValue = false;
}
scrollBarValue = this.radGridView1.TableElement.HScrollBar.Value;
}
private void HScrollBar_ValueChanged(object sender, EventArgs e)
{
if (shouldResetValue)
{
this.radGridView1.TableElement.HScrollBar.Value = scrollBarValue;
}
}
To reproduce:
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "ID", "ParentID");
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("ParentID", typeof(int));
for (int i = 1; i <= 5; i++)
{
dt.Rows.Add(i, "Parent." + i, 0);
}
Random rand = new Random();
for (int i = 6; i < 20; i++)
{
dt.Rows.Add(i, "Child." + i, rand.Next(1, 6));
}
for (int i = 20; i < 40; i++)
{
dt.Rows.Add(i, "SubChild." + i, rand.Next(6, 20));
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
When RadGridView is in right to left mode and the data is grouped, the layout of the items that represent the group field names is incorrect - the close button overlays the text.
WORKAROUND:
public Form83()
{
new RadControlSpyForm().Show();
InitializeComponent();
this.radGridView1.GroupByChanged += radGridView1_GroupByChanged;
}
void radGridView1_GroupByChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
foreach (GroupFieldElement fieldElement in this.radGridView1.GridViewElement.GroupPanelElement.GetDescendants(
delegate(RadElement element) { return element is GroupFieldElement; }, Telerik.WinControls.TreeTraversalMode.BreadthFirst))
{
fieldElement.TextAlignment = ContentAlignment.MiddleRight;
}
}
To reproduce:
Setup RadGridView as follows:
this.Grid.MasterTemplate.EnablePaging = true;
this.Grid.Columns.Add("");
this.Grid.Columns.Add("");
this.Grid.Columns.Add("");
this.Grid.Columns.Add("");
On a button click add rows:
private void Button_Clic9k(object sender, EventArgs e)
{
for (int i = 0; i < 120; i++)
{
this.Grid.Rows.AddNew();
}
}
You will see a vertical scrollbar when it is not needed.
Workaround:
Wrap the loop in a Begin/EndUpdate calls:
private void Button_Clic9k(object sender, EventArgs e)
{
this.Grid.BeginUpdate();
for (int i = 0; i < 120; i++)
{
this.Grid.Rows.AddNew();
}
this.Grid.EndUpdate();
}
Currently one cannot set the column chooser items properties permanently since they are recreated every time the chooser is shown or item is added/removed. Resolution: You can subscribe to the ColumnChooserItemElementCreating event and edit the column chooser items.
To reproduce:
1. Add a RadGridView and a RadButton.
2. Enable paging.
3. Use the code snippet below:
private void Form1_Load(object sender, EventArgs e)
{
this.ordersTableAdapter.Fill(this.nwindDataSet.Orders);
bs.DataSource = this.ordersBindingSource;
this.radGridView1.DataSource = bs;
}
BindingSource bs = new BindingSource();
private void radButton1_Click(object sender, EventArgs e)
{
bs.Filter ="ShipName LIKE '%z%'";
}
4. Navigate to page 80 and click the button.
5. You have only 4 pages available , but you are still positioned on page 80.
Workaround:
private void radButton1_Click(object sender, EventArgs e)
{
bs.Filter ="ShipName LIKE '%z%'";
if (this.radGridView1.MasterTemplate.PageIndex>this.radGridView1.MasterTemplate.TotalPages)
{
this.radGridView1.MasterTemplate.MoveToFirstPage();
}
}
To reproduce: -Add GridViewMaskBoxColumn to a grid. -Set the Mask type to Regex and set any mask you want. -When you leave the cell NullRefernceException is thrown.