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:
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;
}
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;
}
}
If one sets AutoSizeRows to true and AllowSearchRow to true the layout of RadGridView throws an exception.
Resolution: Please use the following code snippet to replace RadGridViewDragDropService: this.radGridView1.GridViewElement.RegisterService(new CustomDragDropService(this.radGridView1.GridViewElement));
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.
To reproduce: - Add the following column to a blank grid and new row or edit the existing one: GridViewMaskBoxColumn maskBoxColumn = new GridViewMaskBoxColumn(); maskBoxColumn.Name = "Dates"; maskBoxColumn.HeaderText = "Dates"; maskBoxColumn.MaskType = MaskType.FreeFormDateTime; maskBoxColumn.DataType = typeof(System.DateTime); radGridView1.MasterTemplate.Columns.Add(maskBoxColumn); this.radGridView1.Rows.Add(DateTime.Now.AddDays(5));
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);
RadGridView, TextBoxColumn - add support for autocomplete.
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);
}
}
Note: it is reproducible when using ColumnGroupsViewDefinition too. Workaround: unpin all pinned columns before printing and restore their state after printing:
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.
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:
public Form1()
{
InitializeComponent();
radGridView1.Columns.Add("Id");
radGridView1.Columns.Add("ParentID");
radGridView1.Columns.Add("Name");
radGridView1.Relations.AddSelfReference(radGridView1.MasterTemplate, "Id", "ParentID");
for (int id = 1; id <= 3; id++)
{
radGridView1.MasterTemplate.Rows.Add(id, 0, "Node_" + id);
for (int iChild = 1; iChild <= 5; iChild++)
{
int childId = id * 100 + iChild;
radGridView1.MasterTemplate.Rows.Add(childId, id, "ChildNode_" + childId);
}
}
foreach (GridViewHierarchyRowInfo row in this.radGridView1.Rows)
{
row.IsExpanded = true;
}
}
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: - Add grid with enabled paging and filtering to a blank form. - Select the second page and apply a filter.
To reproduce: add a RadGridView and bind it to the Northwind.Products data table. Use the following code:
private void Form1_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
RadMessageBox.Show(string.Format("TOTAL2 = {0}", NewExpression()));
}
public string NewExpression()
{
this.radGridView1.Columns.Add(new GridViewDecimalColumn("TOTAL1") { Expression = "ReorderLevel + UnitsOnOrder" });
this.radGridView1.Columns.Add(new GridViewDecimalColumn("TOTAL2") { Expression = "TOTAL1 + UnitPrice" });
//uncomment to get the value of "TOTAL2"
// var total1 = this.radGridView1.Rows[2].Cells["TOTAL1"].Value;
var total2 = this.radGridView1.Rows[2].Cells["TOTAL2"].Value;
return total2.ToString();
}
It is not possible to access the column value ("TOTAL2") before firstly to access the column "TOTAL1" value.
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;
}
}