GridViewCellInfo offers Style property which allows you to customize the style for the cells defined at the data cell's level: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/style-property
This functionality should work for the header cells as well like this:
GridViewCellInfo cell = this.radGridView1.MasterView.TableHeaderRow.Cells[0];
cell.Style.CustomizeFill = true;
cell.Style.GradientStyle = GradientStyles.Solid;
cell.Style.BackColor = System.Drawing.Color.FromArgb(162, 215, 255);
Run the attached sample project on a monitor with 100% DPI scaling. Then, try moving the form to the second monitor with 150% DPI scaling. You will notice that the following error occurs:
Workaround: instead of using a RadTextBoxControlElement in the custom cell, feel free to use a RadTextBoxElement. However, please have in mind that RadTextBoxElement hosts the MS TextBox and using controls in grid cells may slow down the scrolling and will cause visual glitches as they do not support clipping.
ArgumentOutOfRangeException is thrown when the control is auto-sized (AutoSize = true) and we try to select all (MultiSelect = true with CellSelect) rows by clicking and moving the mouse.
As a workaround, we could set the MaximumSize property of the RadGridView.
this.radGridView1.MaximumSize = new Size(1000,1000);
Use the following code snippet:
public RadForm1()
{
InitializeComponent();
this.radGridView1.Columns.Add("TextColumn");
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
for (int i = 0; i < 30; i++)
{
this.radGridView1.Rows.Add(Guid.NewGuid().ToString());
}
this.radGridView1.CellValidating += radGridView1_CellValidating;
this.radGridView1.EditorManager.CloseEditorWhenValidationFails = false;
}
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
if (e.Value == null || e.Value == "")
{
e.Cancel = true;
RadMessageBox.Show("Value can't be empty!");
}
}
Steps:
1. Clear the value of a cell
2. While the editor is active with an empty value, click the vertical scrollbar to trigger scrolling.
Actual: the scrolling is performed and the editor is closed with the previous value no matter when the validation fails and the CloseEditorWhenValidationFails property is set to false.
Expected: the scrolling should be blocked if the validation fails. We should offer the same behavior when scrolling with the mouse wheel, clicking another cell or clicking the vertical scrollbar (or any of its elements).
Workaround:
public class MyGrid : RadGridView
{
public override string ThemeClassName
{
get
{
return typeof(RadGridView).FullName;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
RadScrollBarElement scrollBarAtPoint = GetScrollbarElementAtPoint<RadScrollBarElement>(this.GridViewElement.ElementTree, e.Location) as RadScrollBarElement;
GridViewEditManager editManager = this.EditorManager;
if (scrollBarAtPoint != null && this.ActiveEditor != null && !editManager.CloseEditorWhenValidationFails)
{
bool isClosed = editManager.CloseEditor();
if (!isClosed)
{
return;
}
}
base.OnMouseDown(e);
}
internal T GetScrollbarElementAtPoint<T>(RadElementTree componentTree, Point point) where T : RadElement
{
if (componentTree != null)
{
RadElement elementUnderMouse = componentTree.GetElementAtPoint(point);
while (elementUnderMouse != null)
{
T item = elementUnderMouse as T;
if (item != null)
{
return item;
}
elementUnderMouse = elementUnderMouse.Parent;
}
}
return null;
}
}
Steps to reproduce:
1. Run the sample project and select a row inside the grid
2. Press Ctrl+B
The following error occur:
Workaround: set the EnableFastScrolling property to false.
When we have column groups with equal names, the Spread Export is not exporting the groups correctly. This will lead to incorrectly merged cells.
A possible workaround is to assure that all column groups have different strings for their Text property.
Use the following code:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
for (int i = 0; i < 10; i++)
{
dt.Rows.Add(i, "Item" + i);
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.CellValidating += radGridView1_CellValidating;
}
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
if (e.Column.Index == 0 && e.ActiveEditor != null && e.Value + "" == "1")
{
e.Cancel = true;
RadMessageBox.Show("IncorrectValue");
}
}
Follow the steps:
1. Scroll to the last row.
2. Enter value "1" in the first cell of the last row
3. Click the area above the scrollbar's thumb to trigger scrolling to the top. You will notice that the message box will be shown and the view will be scrolled. Once the message is closed, the error occurs.
Workaround:
public class CustomGridView : RadGridView
{
public override string ThemeClassName
{
get
{
return typeof(RadGridView).FullName;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
RadScrollBarElement scrollbar= this.GridViewElement.ElementTree.GetElementAtPoint ( e.Location) as RadScrollBarElement;
if (scrollbar!=null && this.IsInEditMode)
{
this.EditorManager.CloseEditorWhenValidationFails = false;
this.EditorManager.CloseEditor();
return;
}
base.OnMouseDown(e);
}
}
I might be missing something, but I have Hyperlinks in a column in my RadDatGridView.
I tried searching for a Support document explaining this, but didn't find any.
When the grid is exported to excel all data is coming across, but the column with hyperlink is not
a hyperlink in Excel.
Below is sample of the code used to make the "HyperLink" column in my grid.
radGridView1.DataSource = dtResults;
radGridView1.Columns.Remove("Path");
GridViewHyperlinkColumn col = new GridViewHyperlinkColumn();
radGridView1.Columns.Insert(5, col);
col.Width = 200;
col.FieldName = "Path";
col.HeaderText = "Path";
col.Name = "Path";
Coded used to do the Export....
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
spreadExporter.ExportVisualSettings = true;
SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
spreadExporter.RunExport(filename, exportRenderer);
Thanks.
Roger
Hi
I just found a strange issue using the latest bits of the Telerik RadGridView.
I have a grid that contains ColumnGroupsViewDefinition. Inside one of the group, one of the column is a GridViewComboBoxColumn.
The grid shows correctly on the screen.
If I try to export it using GridViewSpreadExport, I get an exception saying "input string was not in a correct format".
The export works fine if:
-I don't have groups
-I export to HTML using ExportToHTML
-I export to HTML using ExportToCSV
Any help please?
Run the attached project and click List then Export.
Expected:
Actual:
Workaround:
Private Sub RadButton2_Click(sender As Object, e As EventArgs) Handles RadButton2.Click
Dim spreadExporter As GridViewSpreadExport = New GridViewSpreadExport(gvAssetSchedule)
AddHandler spreadExporter.CellFormatting, AddressOf spreadExporter_CellFormatting
Dim exportRenderer As New SpreadExportRenderer()
spreadExporter.ExportVisualSettings = True
Dim filename = "..\..\export" & DateTime.Now.ToLongTimeString().Replace(":", "_") & ".xlsx"
spreadExporter.RunExport(filename, exportRenderer)
Process.Start(filename)
End Sub
Private Sub spreadExporter_CellFormatting(sender As Object, e As Telerik.WinControls.Export.CellFormattingEventArgs)
If e.GridCellInfo Is Nothing Then
Dim selection As CellSelection = e.CellSelection
Dim range As CellRange = selection.CellRanges(0)
Dim val = selection.Worksheet.Cells(range.FromIndex.RowIndex, range.FromIndex.ColumnIndex).GetValue()
Dim format As New CellValueFormat("@")
selection.Worksheet.Cells(range.FromIndex.RowIndex, range.FromIndex.ColumnIndex).SetFormat(format)
Dim dt As New DateTime(1900, 1, 1)
Dim parsedDays = 0
If Integer.TryParse(val.Value.RawValue, parsedDays) Then
dt = dt.AddDays(parsedDays)
selection.Worksheet.Cells(range.FromIndex.RowIndex, range.FromIndex.ColumnIndex).SetValue(dt.Year & "-" & MonthName(dt.Month))
End If
End If
End Sub
Please refer to the below gif file. You will notice that the drop row line is shown only when dropping in the same grip but not when dropping on another grid:
Workaround: use the project in the following forum post: https://www.telerik.com/forums/preview-drop---drag-drop-between-gridview#5477699
Steps to reproduce:
1.Run the attached sample project.
2.Group by the ProductID column
3.Select Page 4
4. Expand the top group row. You will notice that the grid jumps to a previous row.
Expected:
Actual:
Workaround:
public class CustomGrid : RadGridView
{
public override string ThemeClassName
{
get
{
return typeof(RadGridView).FullName;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
GridExpanderItem expander = this.ElementTree.GetElementAtPoint(e.Location) as GridExpanderItem;
if (expander != null)
{
flag = true;
}
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
flag = false;
}
bool flag = false;
protected override void OnPageChanging(object sender, PageChangingEventArgs e)
{
if (flag)
{
e.Cancel = true;
}
base.OnPageChanging(sender, e);
}
}
ComboBox column DataSource property is not visible in the Designer MS Property Builder when the previously selected node was RadGridView.