Makes RadGridView to be thread safe by using from BackgroundWorker
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 a RadGridView with a GridViewComboBoxColumn and add 70000 items as datasource. You will notice that openning it is slow.
Workaround:
Use the following custom editor:
public class MyEditor : RadDropDownListEditor
{
protected override RadElement CreateEditorElement()
{
return new MyEditorElement()
{
SyncSelectionWithText = false
};
}
}
public class MyEditorElement : RadDropDownListEditorElement
{
public override void NotifyOwner(PopupEditorNotificationData notificationData)
{
if (notificationData.notificationContext == PopupEditorNotificationData.Context.TextChanged && !this.SyncSelectionWithText)
{
return;
}
base.NotifyOwner(notificationData);
}
}
If SqlDataReader object has been used for loading data in RadGridView, column expressions does not work.
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: - Add grid with enabled paging and filtering to a blank form. - Select the second page and apply a filter.
IMPROVE. RadGridView - add the current selection and the new selection to the SelectionChanging event.
Provide calculation of the 'Ceiling' function in a column expression: column.Expression = "Ceiling(ColumnName)";
Replacing the RadTextBoxItem with RadTextBoxElement in the RadGridView editor will provide richer theming capabilities.
The HeaderText of the RadGridView column should be set to the caption of the DataTable column Caption when it is provided.
The property will have higher priority than the theme and will be more convenient for using than the ViewCellFormatting event.
Provide options for customization of the columns RadComboBox items.
Added new event in the RadGridView control ConditionalFormattingFormShown fired when the conditionalformattingform is shown.
Added new customization options to ConditionalFormattingForm dialog:
property: SelectFromVisibleColumnsOnly - filter the column selector to display only visible columns in RadGridView
property: ColumnDisplayStyle - display Name or HeaderText or both in column selector
Example:
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace Lab.Grid
{
public partial class GridConditionalFormattingForm : Form
{
private RadGridView gridView = new RadGridView();
public GridConditionalFormattingForm()
{
InitializeComponent();
gridView.Dock = DockStyle.Fill;
gridView.Parent = this;
gridView.MultiSelect = true;
gridView.ConditionalFormattingFormShown += gridView_ConditionalFormattingFormShown;
}
void gridView_ConditionalFormattingFormShown(object sender, System.EventArgs e)
{
ConditionalFormattingForm form = sender as ConditionalFormattingForm;
form.ColumnDisplayStyle = ColumnDisplayStyle.Name | ColumnDisplayStyle.HeaderText;
form.SelectFromVisibleColumnsOnly = true;
}
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
DataTable data = new DataTable();
data.Columns.Add("ID");
data.Columns.Add("Name");
data.Columns.Add("Test3");
data.Rows.Add(1, "Name1", "Test1");
data.Rows.Add(2, "Name2", "Test2");
data.Rows.Add(1, "Name3", "Test3");
data.Rows.Add(4, "Name4", "Test4");
data.Rows.Add(1, "Name5", "Test5");
gridView.DataSource = data;
gridView.Columns[2].IsVisible = false;
gridView.Columns[2].HeaderText = "AlaBala";
ConditionalFormattingObject format = new ConditionalFormattingObject("MyCondition", ConditionTypes.Equal, "1", "", true);
format.CellBackColor = Color.Red;
format.ApplyOnSelectedRows = false;
gridView.Columns[0].HeaderText = "FirstName";
gridView.Columns[0].ConditionalFormattingObjectList.Add(format);
}
}
}
Steps to reproduce:
1) Add RadGridView control
2) Use GridViewDecimalColumn:
DataTable customDataTable = new DataTable();
sampleDataTable.Columns.Add("Column name", typeof(double));
3) Set the right-to-left property of the control to true:
this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
4) Set the following CellElement properties using CellFormatting event:
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement is GridDataCellElement)
{
e.CellElement.RightToLeft = false;
}
}
5) Re-size the form manually until the horizontal scroll-bar disappears
6) Resize a GridHeaderCellElement in left direction and you will notice that the GridDataCellElements from this columns are resized to the right direction
Whenever I'm trying to expand any column the header expands as expected but the column itself is expanding in the other direction so the headers and columns content are not aligned.
Expected result: expand the column content properly
Actual result: the GridDataCellElements from this columns are expanding incorrectly
Typo error - "Lenght" instead of "Length", located under "Text" in the GridView expression editor
To reproduce: - add couple columns in design time - populate them in the form's constructor - subscribe to the cell formatting event where validation will be performed The result is that the indent cell hover displays the error text set and the data cells are formatted correctly, but the exclamation mark is not displayed until the grid is scrolled. It seems that the indent cell is not invalidated WORKAROUND: Call the Refresh method of the template
DateTimeColumn should open hitting the F4 key.
WORKAROUND:
this.radGridView1.EditorRequired += new EditorRequiredEventHandler(radGridView1_EditorRequired);
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
Try to set the number of columns for the RadGridView to greater than 11230 columns, it throws "An item with the same key has already been added." exception. It does not happen when the code is run for the first time, but on any subsequent calls. Step to reproduce:
1. Create project with Windows form
2. Place RadGridView on form
3. Add following code:
private void Form1_Load(object sender, EventArgs e)
{
radGridView1.VirtualMode = true;
radGridView1.ColumnCount = 15000;
}
4. Run application multiple times and you will get an exception at some moment during start up. NO WORKAROUND
STEPS TO REPRODUCE:
1) Create an excel file with sample string values (for example 3x3):
| Value 1 | Value 2 | Value 3 |
| Value 4 | Value 5 | Value 6 |
| Value 7 | Value 8 | Value 9 |
2) Validate as double:
private ErrorProvider errorProvider = new ErrorProvider();
void gridView_CellValidated(object sender, CellValidatedEventArgs e)
{
if (e.Value == null)
{
return;
}
var cell = e.Row.Cells[e.ColumnIndex];
double value = 0;
if (double.TryParse(e.Value.ToString(), out value))
{
cell.ErrorText = string.Empty;
errorProvider.SetError(gridView, string.Empty);
}
else
{
cell.ErrorText = "Wrong input format";
errorProvider.SetError(gridView, "Wrong input format");
}
}
3) Copy the cells from excel and paste them in the grid
Expected result: Validate all cells
Actual result: Only the current cell is being validated and the CellValidated and CellValidating events are not fired for the other cells
WORKAROUND:
public class CustomGridBehavior : BaseGridBehavior
{
Form1 form;
public CustomGridBehavior(Form1 form)
{
this.form = form;
}
public override bool ProcessKey(KeyEventArgs keys)
{
if (keys.KeyCode == Keys.V && keys.Control)
{
GridControl.MasterTemplate.Paste();
foreach (GridViewRowInfo row in GridControl.ChildRows)
{
form.ValidateCell(row.Cells[GridControl.CurrentColumn.Index]);
}
return true;
}
return base.ProcessKey(keys);
}
}
void gridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
foreach (RadMenuItem item in e.ContextMenu.Items)
{
if (item.Text == "Paste")
{
e.ContextMenu.Items.Remove(item);
break;
}
}
RadMenuItem myPasteItem = new RadMenuItem("Paste");
myPasteItem.Click += new EventHandler(myPasteItem_Click);
e.ContextMenu.Items.Add(myPasteItem);
}
void myPasteItem_Click(object sender, EventArgs e)
{
gridView.MasterTemplate.Paste();
foreach (GridViewRowInfo row in gridView.ChildRows)
{
ValidateCell(row.Cells[gridView.CurrentColumn.Index]);
}
}
Create a GridViewComboBoxColumn. When you select the field either by tab or single-click, it is no longer possible to select a value by pressing an alpha-numeric key on keyboard. You must first press the down-arrow key, or select a value with the mouse. Pressing the down-arrow shouldn't be required.