When I add summary rows to my radgridview. something strange is happening. I demonstrate it to you in two pictures. please take a look at attachments
To reproduce: please refer to the attached gif file.
1. Run the attached sample project.
2. Toggle the checkbox and scroll to a specific row.
3. Click the button to hide a column. You will notice that the vertical scrollbar changes its position. If the AutoSizeRows property is set to false, the scrollbar keeps its position.
Workaround:
private void radToggleButton1_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
int scrollBarValue = this.radGridView1.TableElement.VScrollBar.Value;
bool visible = true;
if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
visible = false;
}
this.radGridView1.MasterTemplate.BeginUpdate();
for (int i = 1; i < this.radGridView1.Columns.Count; i += 2)
{
this.radGridView1.Columns[i].IsVisible = visible;
}
this.radGridView1.MasterTemplate.EndUpdate();
this.radGridView1.TableElement.VScrollBar.Value = scrollBarValue;
}
Hi Mostafa, The end users can copy a single cell even when the SelectionMode is set to FullRowSelect via the ContextMenu when opening it on any of the data cells. If the context menu is opened on the row header they will select the whole row. Please check the attached video: radgridview-context-menu-behavior.gif. If you would like to copy a single cell using the Ctrl-C command and have the grid setup in FullRowSelect mode please check the attached project featuring a solution. I am also attaching a video showing the result using the custom implementation in the project: radgridview-full-row-ctrl-c.gif
To reproduce: run the attached sample project and group by the Id column. Workaround: use the ViewCellFormatting event to populate the missing values or use a custom GridViewSummaryItem and override the Evaluate method in order to achieve the desired calculation.
To reproduce:
- Create ColumnGroupsViewDefinition and export it with the following code:
SpreadExportRenderer renderer = new SpreadExportRenderer();
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(radGridView1);
spreadExporter.FreezeHeaderRow = true;
spreadExporter.ExportViewDefinition = true;
spreadExporter.ExportVisualSettings = true;
spreadExporter.ExportGroupedColumns = true;
spreadExporter.ExportHierarchy = true;
spreadExporter.SheetMaxRows = ExcelMaxRows._1048576;
spreadExporter.ExportFormat = SpreadExportFormat.Xlsx;
spreadExporter.FileExportMode = FileExportMode.CreateOrOverrideFile;
spreadExporter.RunExport(dialog.FileName, renderer);
Workaround:
- Set FreezeHeaderRow to false.
You can manually freeze the rows as well:
private void Renderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
{
e.Workbook.ActiveWorksheet.ViewState.FreezePanes(2, 0);
}
To reproduce: run the attached sample project:
1. Clear the value in one of the cells.
2. Select the empty cell and press Ctrl+C to copy the empty cell. You will encounter the error coming from the GetFormattedCellValue method.
Workaround: handle the RadGridView.Copying event
private void RadGridView1_Copying(object sender, GridViewClipboardEventArgs e)
{
if (this.radGridView1.SelectionMode == GridViewSelectionMode.FullRowSelect)
{
foreach (var row in this.radGridView1.SelectedRows)
{
foreach (var cell in row.Cells)
{
GridViewCellInfo cellInfo = cell as GridViewCellInfo;
if (cellInfo != null && cellInfo.Value == null)
{
cellInfo.Value = "";
}
}
}
}
else
{
foreach (var cell in this.radGridView1.SelectedCells)
{
if (cell.Value == null)
{
cell.Value = "";
}
}
}
}
To reproduce:
1. Add a RadGridView with a GridViewCheckBoxColumn and enable the paging functionality for it.
2. Toggle the header checkbox on the first page. Only the rows from the page are toggled.
Workaround: you can subscribe to the HeaderCellToggleStateChanged event and toggle all rows:
private void radGridView1_MouseUp(object sender, MouseEventArgs e)
{
if (this.radGridView1.Tag+""=="toggle")
{
this.radGridView1.Tag = null;
this.radGridView1.HeaderCellToggleStateChanged -= radGridView1_HeaderCellToggleStateChanged;
}
}
private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
RadCheckBoxElement element = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as RadCheckBoxElement;
if (element != null && element.Parent is GridCheckBoxHeaderCellElement)
{
this.radGridView1.Tag = "toggle";
this.radGridView1.HeaderCellToggleStateChanged += radGridView1_HeaderCellToggleStateChanged;
}
}
private void radGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
{
this.radGridView1.BeginUpdate();
foreach (GridViewRowInfo row in this.radGridView1.Rows)
{
row.Cells["Discontinued"].Value = e.State;
}
this.radGridView1.EndUpdate();
}
To reproduce: 1. Run the attached sample project. 2. Move the form to the right bottom of the screen. 3. Hover a cell to show the tool tip. It will start blinking. Please refer to the attached gif file. Workaround: use screen tips: http://docs.telerik.com/devtools/winforms/telerik-presentation-framework/tooltips-and-screentips/screen-tips
How to reproduce:
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.FillData();
this.radGridView1.DataSource = this.dt;
this.radGridView1.EnableSorting = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
this.radGridView1.SortChanged += radGridView1_SortChanged;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
public void FillData()
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 30; i++)
{
dt.Rows.Add(i, "Item" + i);
}
}
private void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.ItemChanged)
{
SortDescriptor s = e.NewItems[0] as SortDescriptor;
string sortOperator = "";
if (s.Direction == ListSortDirection.Ascending)
{
sortOperator = "ASC";
}
else
{
sortOperator = "DESC";
}
dt.DefaultView.Sort = s.PropertyName + " " + sortOperator;
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
dt.DefaultView.Sort = "";
}
}
}
Workaround:
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.FillData();
this.radGridView1.DataSource = this.dt;
this.radGridView1.EnableSorting = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.CellBeginEdit += RadGridView1_CellBeginEdit;
this.radGridView1.CellEndEdit += RadGridView1_CellEndEdit;
}
private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
if (e.Row is GridViewFilteringRowInfo)
{
this.radGridView1.MasterTemplate.DataView.BypassSort = true;
}
}
private void RadGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
{
if (e.Row is GridViewFilteringRowInfo)
{
this.radGridView1.MasterTemplate.DataView.BypassSort = false;
}
}
public void FillData()
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 30; i++)
{
dt.Rows.Add(i, "Item" + i);
}
}
}
To reproduce:
1. Add a GridViewCheckBoxColumn with EnableHeaderCheckBox property set to true.
2. Use the TypeConverter demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types
When you run the application and try to toggle the check box in the header cell, a FormatException occurs.
Workaround: modify the TypeConverter:
public class ToggleStateConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(ToggleState);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
char charValue = (char)value;
switch (charValue)
{
case 'Y':
return ToggleState.On;
case 'N':
return ToggleState.Off;
case 'M':
return ToggleState.Indeterminate;
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(ToggleState) || sourceType == typeof(bool);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
ToggleState state;
bool boolValue;
if (value is ToggleState)
{
state = (ToggleState)value ;
switch (state)
{
case ToggleState.On:
return 'Y';
case ToggleState.Off:
return 'N';
case ToggleState.Indeterminate:
return 'M';
}
}
else if (value is bool)
{
boolValue = (bool)value;
switch (boolValue)
{
case true:
return 'Y';
case false:
return 'N';
default:
return 'M';
}
}
return base.ConvertFrom(context, culture, value);
}
}
To reproduce:
public RadForm1()
{
InitializeComponent();
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.FilterPopupRequired += radGridView1_FilterPopupRequired;
}
private void radGridView1_FilterPopupRequired(object sender, Telerik.WinControls.UI.FilterPopupRequiredEventArgs e)
{
e.FilterPopup.PopupOpening -= FilterPopup_PopupOpening;
e.FilterPopup.PopupOpening += FilterPopup_PopupOpening;
}
private void FilterPopup_PopupOpening(object sender, CancelEventArgs args)
{
args.Cancel = true;
}
Workaround: either set the ShowHeaderCellButtons property to false or closed the popup immediately after it is opened.
private void radGridView1_FilterPopupRequired(object sender, Telerik.WinControls.UI.FilterPopupRequiredEventArgs e)
{
e.FilterPopup.PopupOpening -= FilterPopup_PopupOpening;
e.FilterPopup.PopupOpening += FilterPopup_PopupOpening;
}
private void FilterPopup_PopupOpening(object sender, CancelEventArgs args)
{
RadListFilterPopup popup = sender as RadListFilterPopup;
popup.PopupOpened -= popup_PopupOpened;
popup.PopupOpened += popup_PopupOpened;
}
private void popup_PopupOpened(object sender, EventArgs args)
{
RadListFilterPopup popup = sender as RadListFilterPopup;
popup.ClosePopup(RadPopupCloseReason.Mouse);
}
To reproduce: - Add 7-8 columns to the grid. - Set the AutoSizeColumnsMode to Fill - Set the MaxWidth/MaxWidth of the last two columns. - Resize the first column. - Sometimes the size of the other columns is randomly increased/decreased.
Use attached to reproduce.
This is not an issue. Performing Begin/End update disposes of all elements along with the globally declared item. You need to check if the item is disposed of:
void ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
if (menuItem.IsDisposed)
{
menuItem = new RadMenuItem();
menuItem.Text = "Custom menu item";
menuItem.Click += menuItem_Click;
}
e.ContextMenu.Items.Add(menuItem);
}
Use attached to reproduce.
Workaround:
class MyDataCellElement : GridDataCellElement
{
public MyDataCellElement(GridViewColumn col, GridRowElement row) : base(col,row)
{ }
protected override List<CharacterRange> GetSearchHighlightRanges()
{
// return base.GetSearchHighlightRanges();
List<CharacterRange> ranges = new List<CharacterRange>();
if (this.ColumnInfo == null || !this.RowInfo.SearchCache.Contains(this.ColumnInfo))
{
return ranges;
}
string criteria = this.RowInfo.SearchCache[this.ColumnInfo] as string;
int index = -1;
CompareOptions options;
if (this.MasterTemplate.MasterViewInfo.TableSearchRow.CaseSensitive)
{
options = CompareOptions.Ordinal;
}
else
{
options = this.MasterTemplate.MasterViewInfo.TableSearchRow.CompareOptions;
}
do
{
if (index + 1 >= this.Text.Length)
{
break;
}
index = this.MasterTemplate.MasterViewInfo.TableSearchRow.Culture.CompareInfo.IndexOf(this.Text, criteria, index + 1, options);
if (index >= 0)
{
var str = this.Text.Substring(index, criteria.Length);
int symbolCount = 0;
foreach (char ch in str)
{
if (!Char.IsLetterOrDigit(ch))
{
symbolCount++;
}
}
ranges.Add(new CharacterRange(index, criteria.Length + symbolCount));
}
} while (index >= 0 && ranges.Count < 32);
return ranges;
}
}
private void MasterTemplate_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridDataCellElement))
{
e.CellElement = new MyDataCellElement(e.Column, e.Row);
}
}
To reproduce: please refer to the attached gif file and sample project Workaround: set the AutoSizeRows property to false
To reproduce: run the project, select the grid and press Tab. You will notice a message box for the first grid which won't be shown for the second in the popup.
To reproduce: please refer to the attached gif file and sample project.
Workaround:
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
if (editor!=null)
{
RadDropDownListEditorElement el = editor.EditorElement as RadDropDownListEditorElement;
el.AutoCompleteSuggest.DropDownList.ClosePopup();
}
}
How to reproduce: check the attached video
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData(1000);
this.radGridView1.AutoExpandGroups = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.EnablePaging = true;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
private DataTable GetData(int count)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Bool", typeof(bool));
for (int i = 0; i < count; i++)
{
dt.Rows.Add(i,"Name " + i, DateTime.Now.AddDays(i), i % 2 == 0 ? true : false);
}
return dt;
}
}
Workaround: cancel the PageChanging event
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData(1000);
this.radGridView1.AutoExpandGroups = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.EnablePaging = true;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
timer = new Timer();
timer.Interval = 100;
timer.Tick += (sender, e) =>
{
timer.Stop();
this.shouldCancel = false;
};
this.radGridView1.PageChanging += RadGridView1_PageChanging;
this.radGridView1.CurrentRowChanged += RadGridView1_CurrentRowChanged;
}
private void RadGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
this.shouldCancel = this.ShouldCancelPageChange(e.CurrentRow);
timer.Start();
}
Timer timer;
bool shouldCancel = false;
private bool ShouldCancelPageChange(GridViewRowInfo rowInfo)
{
if (this.radGridView1.TableElement.MasterTemplate != null && this.radGridView1.TableElement.MasterTemplate.EnablePaging)
{
int pageIndex = this.radGridView1.TableElement.ViewTemplate.DataView.GetItemPage(rowInfo);
if (pageIndex == this.radGridView1.TableElement.MasterTemplate.PageIndex)
{
return true;
}
}
return false;
}
private void RadGridView1_PageChanging(object sender, Telerik.WinControls.PageChangingEventArgs e)
{
e.Cancel = this.shouldCancel;
}
private DataTable GetData(int count)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Bool", typeof(bool));
for (int i = 0; i < count; i++)
{
dt.Rows.Add(i,"Name " + i, DateTime.Now.AddDays(i), i % 2 == 0 ? true : false);
}
return dt;
}
}