To reproduce:
Sub New()
InitializeComponent()
ThemeResolutionService.ApplicationThemeName = "Breeze"
Dim dt As New DataTable
dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("ParentId", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
For index = 1 To 5
dt.Rows.Add(index, 0, "Parent" & index)
Next
Dim rand As New Random
For index = 6 To 25
dt.Rows.Add(index, rand.Next(1, 6), "Parent" & index)
Next
Me.RadGridView1.Relations.AddSelfReference(Me.RadGridView1.MasterTemplate, "Id", "ParentId")
Me.RadGridView1.DataSource = dt
Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
Me.RadGridView1.AutoSizeRows = True
End Sub
To reproduce:
private void radButton1_Click(object sender, EventArgs e)
{
radGridView1.Rows[0].Cells[0].Value = false;
}
private void Form1_Load(object sender, EventArgs e)
{
radGridView1.AllowSearchRow = true;
radGridView1.TableElement.SearchHighlightColor = Color.Orange;
radGridView1.AutoExpandGroups = true;
DataTable dt = new DataTable();
dt.Columns.Add("test", typeof(bool));
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
dt.Rows.Add(true);
radGridView1.DataSource = dt;
((Telerik.WinControls.UI.GridViewCheckBoxColumn) radGridView1.Columns[0]).EnableHeaderCheckBox = true;
((Telerik.WinControls.UI.GridViewCheckBoxColumn) radGridView1.Columns[0]).Width = radGridView1.Width - 50;
radGridView1.TableElement.Update(Telerik.WinControls.UI.GridUINotifyAction.Reset); //force header checkbox to check
radGridView1.TableElement.ScrollTo(15, 0);
}
Workaround:
private void radButton1_Click(object sender, EventArgs e)
{
radGridView1.Rows[0].Cells[0].Value = false;
radGridView1.TableElement.Update(Telerik.WinControls.UI.GridUINotifyAction.Reset); //force header checkbox to check
}
To reproduce:
private void Form1_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.Columns["UnitPrice"].FormatString = "{0:$#,###0.00;-$#,###0.00;$0.00}";
}
Workaround: in order to format the cells, use the CellFormatting event. As to the filter popup, use the following approach:
this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;
private void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e)
{
RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
if (popup != null)
{
popup.MenuTreeElement.TreeView.NodeFormatting -= TreeView_NodeFormatting;
popup.MenuTreeElement.TreeView.NodeFormatting += TreeView_NodeFormatting;
}
}
private void TreeView_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
decimal price;
if (decimal.TryParse(e.Node.Text, out price))
{
e.NodeElement.ContentElement.Text = string.Format("{0:$#,###0.00;-$#,###0.00;$0.00}", price);
}
}
Please refer to the attached project. Workakround: call the BeginEdit method in the RadGridView.Click event.
To reproduce: setup the hierarchy at design time: http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/tutorial-binding-to-hierarchical-data Please refer to the attached gif file illustrating the exact steps. NOTE: when the "Object does not match target type" error message is displayed, some of the properties are missing, e.g. MaxLength. Workaround: modify the columns' properties at run time.
To reproduce: follow the steps illustrated in the attached gif file.
To reproduce:
private void Form1_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
this.radGridView1.BestFitColumns(BestFitColumnMode.AllCells);
}
private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement is GridGroupContentCellElement)
{
e.CellElement.TextWrap = true;
}
else
{
e.CellElement.ResetValue(LightVisualElement.TextWrapProperty, ValueResetFlags.Local);
}
}
Workaround: set the AutoSizeColumnsMode property to GridViewAutoSizeColumnsMode.Fill and use the ViewCellFormatting event to wrap the text:
private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement is GridGroupContentCellElement)
{
e.CellElement.TextWrap = true;
}
else
{
e.CellElement.ResetValue(LightVisualElement.TextWrapProperty, ValueResetFlags.Local);
}
}
How to reproduce:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetData();
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Columns[0].DisableHTMLRendering = false;
this.radGridView1.PrintCellFormatting += radGridView1_PrintCellFormatting;
}
private void radGridView1_PrintCellFormatting(object sender, Telerik.WinControls.UI.PrintCellFormattingEventArgs e)
{
e.PrintCell.EnableHtmlTextRendering = true;
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Bool", typeof(bool));
dt.Columns.Add("Description", typeof(string));
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 5; j++)
{
dt.Rows.Add(@"<html><b>Name " + j, DateTime.Now.AddDays(i), i % 2 == 0 ? true : false, "Description " + i);
}
}
return dt;
}
private void radButton1_Click(object sender, EventArgs e)
{
GridPrintStyle style = new GridPrintStyle();
style.FitWidthMode = PrintFitWidthMode.FitPageWidth;
style.PrintGrouping = true;
style.PrintSummaries = false;
style.PrintHeaderOnEachPage = true;
style.PrintHiddenColumns = false;
style.CellPadding = new Padding(100, 0, 0, 0);
this.radGridView1.PrintStyle = style;
this.radGridView1.PrintPreview();
}
}
Workaround: refer to the attached project
To reproduce:
this.radGridView1.EnableFiltering = true;
this.radGridView1.Columns.Add("Test column");
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Rows.Add("Test ");
Workaround: use custom filtering:
this.radGridView1.EnableCustomFiltering = true;
this.radGridView1.CustomFiltering += radGridView1_CustomFiltering;
private void radGridView1_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
{
if (this.radGridView1.FilterDescriptors.Count > 0)
{
GridViewCellInfo cell = e.Row.Cells[this.radGridView1.FilterDescriptors[0].PropertyName];
e.Visible = cell.Value.ToString().StartsWith(this.radGridView1.FilterDescriptors[0].Value.ToString());
}
}
To reproduce: populate RadGridView with data and use the following code snippet:
Me.RadGridView1.TableElement.TableHeaderHeight = 60
RadGridView1.PrintPreview()
Workaround:
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Me.RadGridView1.TableElement.TableHeaderHeight = 60
Dim printStyle As GridPrintStyle = New GridPrintStyle(RadGridView1)
Dim renderer As CustomTableViewDefinitionPrintRenderer = New CustomTableViewDefinitionPrintRenderer(RadGridView1)
printStyle.PrintRenderer = renderer
RadGridView1.PrintStyle = printStyle
RadGridView1.PrintPreview()
End Sub
Public Class CustomTableViewDefinitionPrintRenderer
Inherits TableViewDefinitionPrintRenderer
Public Sub New(grid As RadGridView)
MyBase.New(grid)
End Sub
Private Function GetRowLayout(row As GridViewRowInfo, fitWidthMode As PrintFitWidthMode, _
hierarchyIndent As Integer, drawArea As Rectangle) As TableViewRowLayout
Dim hashKey As Integer = row.ViewTemplate.GetHashCode() + row.HierarchyLevel
Dim fi As FieldInfo = GetType(TableViewDefinitionPrintRenderer).GetField("rowLayouts", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim rowLayouts As Dictionary(Of Integer, TableViewRowLayout) = fi.GetValue(Me)
If rowLayouts.ContainsKey(hashKey) Then
Return rowLayouts(hashKey)
End If
Dim table As GridTableElement = TryCast(row.ViewTemplate.ViewDefinition.CreateViewUIElement(row.ViewInfo), GridTableElement)
table.Initialize(Me.GridView.GridViewElement, row.ViewInfo)
table.RowHeight = Me.GridView.TableElement.RowHeight
table.TableHeaderHeight = Me.GridView.TableElement.TableHeaderHeight
Me.GridView.ElementTree.ApplyThemeToElement(table)
Dim rowLayout As New TableViewRowLayout()
rowLayout.Context = GridLayoutContext.Printer
rowLayout.Initialize(table)
Dim systemWidth As Integer = 0
For Each c As GridViewColumn In rowLayout.RenderColumns
If TypeOf c Is GridViewRowHeaderColumn OrElse TypeOf c Is GridViewIndentColumn Then
systemWidth += rowLayout.GetColumnWidth(c)
End If
Next
Me.GridView.BeginUpdate()
Dim mode As GridViewAutoSizeColumnsMode = rowLayout.ViewTemplate.AutoSizeColumnsMode
If fitWidthMode = PrintFitWidthMode.FitPageWidth Then
Dim state As ColumnsState = Me.SaveColumnsState(rowLayout.ViewTemplate)
rowLayout.ViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
Dim groupLevel As Integer = If(row.Group IsNot Nothing, row.Group.Level + 1, 0)
rowLayout.MeasureRow(New SizeF(drawArea.Width + systemWidth - ((row.HierarchyLevel - groupLevel) * hierarchyIndent), drawArea.Height))
Me.RestoreColumnsState(state)
Else
rowLayout.ViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
rowLayout.MeasureRow(New SizeF(Me.GridView.Width, Me.GridView.Height))
End If
rowLayout.ViewTemplate.AutoSizeColumnsMode = mode
Me.GridView.EndUpdate(False)
rowLayouts.Add(hashKey, rowLayout)
Return rowLayout
End Function
Public Overrides Sub DrawPage(traverser As PrintGridTraverser, drawArea As Rectangle, _
graphics As Graphics, settings As GridPrintSettings, pageNumber As Integer)
Dim fi As FieldInfo = GetType(TableViewDefinitionPrintRenderer).GetField("currentPage", BindingFlags.Instance Or BindingFlags.NonPublic)
Dim currentPage As Integer = fi.GetValue(Me)
Dim skipPage As Boolean = currentPage <> pageNumber
Dim drawAreaHeight As Integer = drawArea.Height
Dim currentX As Integer = drawArea.X
Dim currentY As Integer = drawArea.Y
Dim rowLayout As TableViewRowLayout = Me.GetRowLayout(Me.GridView.MasterView.TableHeaderRow, _
settings.FitWidthMode, settings.HierarchyIndent, drawArea)
rowLayout.IgnoreColumnVisibility = settings.PrintHiddenColumns
Dim systemWidth As Integer = 0
For Each c As GridViewColumn In rowLayout.RenderColumns
If TypeOf c Is GridViewRowHeaderColumn OrElse TypeOf c Is GridViewIndentColumn Then
systemWidth += rowLayout.GetColumnWidth(c)
End If
Next
Dim rowWidth As Integer = CInt(rowLayout.DesiredSize.Width) - systemWidth
If settings.FitWidthMode = PrintFitWidthMode.NoFitCentered Then
currentX += ((drawArea.Width - rowWidth) / 2)
End If
Dim fi2 As FieldInfo = GetType(TableViewDefinitionPrintRenderer).GetField("firstPage", _
BindingFlags.Instance Or BindingFlags.NonPublic)
Dim firstPage As Integer = fi2.GetValue(Me)
If ((Me.GridView.ShowColumnHeaders AndAlso (firstPage AndAlso pageNumber = 1)) OrElse settings.PrintHeaderOnEachPage) _
AndAlso Not settings.PrintHierarchy Then
Me.PrintRow(Me.GridView.MasterView.TableHeaderRow, rowLayout, settings, currentX, currentY, graphics, _
drawArea)
Dim rowHeight As Integer = Me.GetDataRowHeight(Me.GridView.MasterView.TableHeaderRow, rowLayout) + Me.GridView.TableElement.RowSpacing
currentY += rowHeight
drawAreaHeight -= rowHeight
End If
fi2.SetValue(Me, False)
Dim skipPageCurrentY As Integer = currentY
Dim row As GridViewRowInfo = Nothing
If Me.PrintPages.Count > 0 AndAlso Not settings.PrintHierarchy Then
row = traverser.Current
End If
Dim firstRow As Boolean = True
While traverser.MoveNext()
If Not (TypeOf traverser.Current Is GridViewDataRowInfo OrElse TypeOf traverser.Current Is GridViewGroupRowInfo OrElse _
TypeOf traverser.Current Is GridViewSummaryRowInfo OrElse (TypeOf traverser.Current Is GridViewTableHeaderRowInfo _
AndAlso settings.PrintHierarchy)) Then
Continue While
End If
Dim hierarchyRow As GridViewHierarchyRowInfo = TryCast(traverser.Current, GridViewHierarchyRowInfo)
If hierarchyRow IsNot Nothing AndAlso hierarchyRow.Views.Count > 0 Then
Select Case settings.ChildViewPrintMode
Case ChildViewPrintMode.PrintFirstView
hierarchyRow.ActiveView = hierarchyRow.Views(0)
Exit Select
Case ChildViewPrintMode.PrintCurrentlyActiveView
'Do nothing the view is already selected
Exit Select
Case ChildViewPrintMode.SelectViewToPrint
Dim e As New ChildViewPrintingEventArgs(hierarchyRow.Views.IndexOf(hierarchyRow.ActiveView), hierarchyRow)
Me.OnChildViewPrinting(e)
hierarchyRow.ActiveView = hierarchyRow.Views(e.ActiveViewIndex)
Exit Select
End Select
End If
rowLayout = Me.GetRowLayout(traverser.Current, settings.FitWidthMode, settings.HierarchyIndent, drawArea)
Dim rowHeight As Integer = 0
If TypeOf traverser.Current Is GridViewGroupRowInfo Then
rowHeight = Me.GetRowSize(traverser.Current, rowLayout).Height
Else
rowHeight = Me.GetDataRowHeight(traverser.Current, rowLayout)
End If
If (currentY + rowHeight >= drawArea.Bottom OrElse skipPageCurrentY + rowHeight >= drawArea.Bottom) AndAlso Not firstRow Then
traverser.MovePrevious()
skipPageCurrentY = currentY
skipPage = currentPage <> pageNumber
fi.SetValue(Me, currentPage + 1)
If skipPage Then
Continue While
Else
Exit While
End If
End If
If TypeOf traverser.Current Is GridViewGroupRowInfo Then
If settings.PrintGrouping Then
If currentPage = pageNumber Then
Me.PrintRowWideCell(traverser.Current, rowLayout, settings, currentX, currentY, graphics)
currentY += rowHeight + Me.GridView.TableElement.RowSpacing
Else
skipPageCurrentY += rowHeight + Me.GridView.TableElement.RowSpacing
End If
End If
Else
If TypeOf traverser.Current Is GridViewSummaryRowInfo AndAlso Not settings.PrintSummaries Then
Continue While
End If
If currentPage = pageNumber Then
Me.PrintRow(traverser.Current, rowLayout, settings, currentX, currentY, graphics, _
drawArea)
currentY += rowHeight + Me.GridView.TableElement.RowSpacing
Else
skipPageCurrentY += rowHeight + Me.GridView.TableElement.RowSpacing
End If
End If
If drawAreaHeight < rowHeight AndAlso firstRow Then
fi.SetValue(Me, currentPage + 1)
Exit While
End If
firstRow = False
End While
If Me.PrintPages.Count > 0 AndAlso Not settings.PrintHierarchy Then
If currentY + Me.GetDataRowHeight(traverser.Current, rowLayout) < drawArea.Bottom OrElse _
skipPageCurrentY + Me.GetDataRowHeight(traverser.Current, rowLayout) < drawArea.Bottom Then
fi.SetValue(Me, currentPage + 1)
End If
Me.CurrentPrintPage += 1
Me.CurrentPrintPage = Me.CurrentPrintPage Mod Me.PrintPages.Count
If Me.CurrentPrintPage > 0 Then
If row Is Nothing Then
traverser.Reset()
Else
traverser.GoToRow(row)
End If
End If
End If
End Sub
End Class
To reproduce:
Open the attached project, select two rows and delete them.
Workaround:
private void RadGridView1_RowValidating(object sender, Telerik.WinControls.UI.RowValidatingEventArgs e)
{
if (e.RowIndex != -1)
{
}
}
To reproduce:
- Bind the grid and reset its data source in the CellValueChanged event handler.
- Start the application, click in a cell, delete the contents and right click a header cell.
- Exception is thrown.
Workaround:
class MyGridHeaderCellElement : GridHeaderCellElement
{
public MyGridHeaderCellElement(GridViewColumn col, GridRowElement row) : base(col, row)
{ }
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridHeaderCellElement);
}
}
protected override void ShowContextMenu()
{
if (this.ViewTemplate != null)
{
base.ShowContextMenu();
}
}
}
private void RadGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
if (e.CellType == typeof(GridHeaderCellElement))
{
e.CellType = typeof(MyGridHeaderCellElement);
}
}
To reproduce: - Bind the grid to progress binding source at design time. - Locate GroupDescriptors in Properties and click the ellipsis button to open the GroupDescriptor Collection Editor. - Click Add and select the new item. - Select the GroupNames collection to open the SortDescriptor Collection Editor. - Click Add. - An exception is thrown and the UI freezes. Workaround: Add descriptors at runime.
To reproduce: please refer to the attached sample project.
1. Edit the CommonInt property for the first child row.
2. Edit the CommonInt property for the second child row.
Workaround: Add the grid programmatically at run time.
Second Workaround:
this.radGridView1.CellValueChanged+=radGridView1_CellValueChanged;
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
e.Column.OwnerTemplate.Refresh(e.Column);
}
To reproduce:
- Add DateTime column and set the RowHeight to 20.
- Set the theme to Windows7.
- The text is not visible when the editor is shown.
Workaround:
private void RadGridView2_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor != null)
{
var element = editor.EditorElement as RadDateTimeEditorElement;
element.Font = new Font("Segoe UI", 8, FontStyle.Regular);
element.Children[1].Visibility = ElementVisibility.Collapsed;
element.TextBoxElement.ShowBorder = false;
element.TextBoxElement.TextBoxItem.HostedControl.MinimumSize = new Size(0, 12);
}
}
How to reproduce:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radGridView1.DataSource = this.GetSampleData();
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.ShowHeaderCellButtons = true;
}
private DataTable GetSampleData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(double));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("IsValid", typeof(bool));
dt.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < 115; i++)
{
dt.Rows.Add(((double)i * 5 / 7) * 3, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(i));
}
return dt;
}
}
Workaround specify decimal as the type of the column in the DataTable object or clone the DataTAble object and change the type of the column:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTable dt = this.GetSampleData();
DataTable dtCloned = dt.Clone();
dtCloned.Columns[0].DataType = typeof(decimal);
foreach (DataRow row in dt.Rows)
{
dtCloned.ImportRow(row);
}
this.radGridView1.DataSource = dtCloned;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.ShowHeaderCellButtons = true;
}
private DataTable GetSampleData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(double));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("IsValid", typeof(bool));
dt.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < 115; i++)
{
dt.Rows.Add(((double)i * 5 / 7) * 3, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(i));
}
return dt;
}
}
To reproduce:
public Form1()
{
InitializeComponent();
List<Item> items = new List<Item>();
for (int i = 0; i < 10; i++)
{
items.Add(new Item(i,"Item" + i,Color.Red));
}
this.radGridView1.DataSource = items;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.CellValidating += radGridView1_CellValidating;
}
private void radGridView1_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
{
if (e.ActiveEditor != null && e.ActiveEditor is GridColorPickerEditor)
{
Color c = (Color)e.Value;
if (c == Color.Red)
{
e.Cancel = true;
Console.WriteLine("Red is not allowed!");
}
}
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public Color Color { get; set; }
public Item(int id, string name, Color color)
{
this.Id = id;
this.Name = name;
this.Color = color;
}
}
Steps:
1. Activate the editor for the Color cell.
2. Leave the color as it
3. Press the Enter key. The CellValidating event is fired twice.
Note: it seems that when the color text is selected, the event is fired twice.
Please refer to the attached sample project and gif files. The user is not allowed to drop in the first half of the row element. However, the drop operation is allowed in the second half. Once the RadDragOverEventArgs.CanDrop property is set to false, the before/after row hint is disposed and it is not shown for this row anymore.
Workaround:
public class CustomRadGridViewDragDropService : RadGridViewDragDropService
{
public CustomRadGridViewDragDropService(RadGridViewElement gridViewElement) : base(gridViewElement)
{
}
public override string Name
{
get
{
return typeof(RadGridViewDragDropService).Name;
}
}
protected override void OnPreviewDragOver(RadDragOverEventArgs e)
{
base.OnPreviewDragOver(e);
SetDragDropBehavior();
Point p = this.GridViewElement.ElementTree.Control.PointToClient(Cursor.Position);
UpdateDragHintLocation(p);
}
}
this.radGridView1.GridViewElement.RegisterService(new CustomRadGridViewDragDropService(this.radGridView1.GridViewElement));
To reproduce:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
Me.RadGridView1.DataSource = Me.CategoriesBindingSource
Dim viewDef As New ColumnGroupsViewDefinition
Dim group1 = New GridViewColumnGroup()
Dim row1 = New GridViewColumnGroupRow
group1.Rows.Add(row1)
row1.ColumnNames.Add("CategoryID")
row1.ColumnNames.Add("CategoryName")
viewDef.ColumnGroups.Add(group1)
Dim group2 = New GridViewColumnGroup()
Dim row2 = New GridViewColumnGroupRow
group2.Rows.Add(row2)
row2.ColumnNames.Add("Description")
row2.ColumnNames.Add("Picture")
viewDef.ColumnGroups.Add(group2)
Me.RadGridView1.ViewDefinition = viewDef
End Sub
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Console.WriteLine("BEFORE >>")
For Each col As GridViewColumn In Me.RadGridView1.Columns
Console.WriteLine(col.Name & " >> " & col.Width )
Next
Dim style As New GridPrintStyle()
style.FitWidthMode = PrintFitWidthMode.FitPageWidth
Me.RadGridView1.PrintStyle = style
Me.RadGridView1.PrintPreview()
Console.WriteLine("AFTER >>")
For Each col As GridViewColumn In Me.RadGridView1.Columns
Console.WriteLine(col.Name & " >> " & col.Width)
Next
End Sub
IMPORTANT: If you resize one of the columns at run time before calling the PrintPreview method, the columns' width is restored. In addition, if you call the PrintPreview method without resizing the columns before that, close the dialog and hide one of the columns by using the default context menu, the columns' width for the visible columns is enlarged.
Workaround: you can get the columns width by using the ColumnGroupRowLayout:
Dim rowLayout As ColumnGroupRowLayout = TryCast(Me.RadGridView1.TableElement.ViewElement.RowLayout, ColumnGroupRowLayout)
For Each col As GridViewColumn In Me.RadGridView1.Columns
Dim info As ColumnGroupsCellArrangeInfo = rowLayout.GetColumnData(col)
Debug.WriteLine(col.Name & " >> " & info.Bounds.Width)
Next
To reproduce:
public RadForm1()
{
InitializeComponent();
DataTable master = new DataTable();
master.Columns.Add("ID", typeof(int));
master.Columns.Add("test", typeof(string));
for (int i = 0; i < 500; i++)
{
master.Rows.Add(i, "Row " + i);
}
radGridView1.DataSource = master;
radLabel1.Text = "RadGridView: AutoSizeRows = " + ((radGridView1.AutoSizeRows) ? "True" : "False");
}
private void radButton1_Click(object sender, EventArgs e)
{
radGridView1.TableElement.ScrollToRow(radGridView1.MasterTemplate.Rows[200]);
}
private void radButton2_Click(object sender, EventArgs e)
{
radGridView1.AutoSizeRows = !radGridView1.AutoSizeRows;
radLabel1.Text = "RadGridView: AutoSizeRows = " + ((radGridView1.AutoSizeRows) ? "True" : "False");
}
Workaround:
this.radGridView1.ViewDefinition = new CustomTableViewDefinition();
public class CustomTableViewDefinition : TableViewDefinition
{
public override IRowView CreateViewUIElement(GridViewInfo viewInfo)
{
return new CustomGridTableElement();
}
}
public class CustomGridTableElement : GridTableElement
{
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridTableElement);
}
}
public override void ScrollToRow(GridViewRowInfo rowInfo)
{
if (rowInfo == null || rowInfo.IsPinned || !rowInfo.IsVisible || rowInfo is GridViewDetailsRowInfo)
{
return;
}
this.ViewElement.InvalidateMeasure();
this.ViewElement.UpdateLayout();
if (GridViewElement.AutoSizeRows || (ViewTemplate.Templates.Count > 0 && rowInfo.ViewTemplate.Parent != null))
{
ScrollToRowCore(rowInfo, false);
return;
}
this.RowScroller.ScrollToItem(rowInfo, false);
this.UpdateLayout();
}
private void ScrollToRowCore(GridViewRowInfo rowInfo, bool ensureVisible)
{
if (!this.GridViewElement.UseScrollbarsInHierarchy && this.ViewInfo.ParentRow != null)
{
if (ensureVisible)
{
this.GridViewElement.TableElement.EnsureRowVisible(rowInfo);
}
else
{
this.GridViewElement.TableElement.ScrollToRow(rowInfo);
}
return;
}
if (!this.IsInValidState(true) || this.VScrollBar.LargeChange == 0)
{
return;
}
RadControl control = this.ElementTree.Control as RadControl;
if (control != null)
{
control.SuspendUpdate();
}
int oldValue = this.VScrollBar.Value;
GridRowElement rowElement = GetChildRowElement(rowInfo);
if (rowElement == null && this.PageViewMode == PageViewMode.ExplorerBar)
{
if (control != null)
{
control.ResumeUpdate();
}
return;
}
while (this.VScrollBar.Value < this.VScrollBar.Maximum)
{
if (rowElement == null)
{
rowElement = GetChildRowElement(rowInfo);
}
if (rowElement != null)
{
ScrollToPartiallyVisibleRow(rowElement, ensureVisible);
break;
}
else
{
bool scrollRangeChanged = SetScrollValue(this.VScrollBar, this.VScrollBar.Value + this.VScrollBar.SmallChange);
if (this.VScrollBar.Value >= this.VScrollBar.Maximum - this.VScrollBar.LargeChange + 1 && !scrollRangeChanged)
{
SetScrollValue(this.VScrollBar, oldValue);
break;
}
}
}
if (oldValue == this.VScrollBar.Minimum || rowElement != null)
{
if (control != null)
{
control.ResumeUpdate();
}
return;
}
SetScrollValue(this.VScrollBar, 0);
while (this.VScrollBar.Value < oldValue)
{
if (rowElement == null)
{
rowElement = GetChildRowElement(rowInfo);
}
if (rowElement != null)
{
ScrollToPartiallyVisibleRow(rowElement, ensureVisible);
break;
}
else
{
bool scrollRangeChanged = SetScrollValue(this.VScrollBar, this.VScrollBar.Value + this.VScrollBar.SmallChange);
if (this.VScrollBar.Value >= this.VScrollBar.Maximum - this.VScrollBar.LargeChange + 1 && !scrollRangeChanged)
{
SetScrollValue(this.VScrollBar, oldValue);
break;
}
}
}
if (control != null)
{
control.ResumeUpdate();
}
}
private GridRowElement GetChildRowElement(GridViewRowInfo rowInfo)
{
if (rowInfo.ViewInfo == this.ViewInfo)
{
return GetRowElement(rowInfo);
}
else
{
GridTableElement tableElement = GridViewElement.GetRowView(rowInfo.ViewInfo) as GridTableElement;
if (tableElement != null)
{
return tableElement.GetRowElement(rowInfo);
}
}
return null;
}
private void ScrollToPartiallyVisibleRow(GridRowElement rowElement, bool ensureVisible)
{
int delta = 0;
while ((rowElement.ControlBoundingRectangle.Y < ViewElement.ScrollableRows.ControlBoundingRectangle.Y &&
rowElement.ControlBoundingRectangle.Bottom > ViewElement.ScrollableRows.ControlBoundingRectangle.Y) ||
(rowElement.ControlBoundingRectangle.Y < ViewElement.ScrollableRows.ControlBoundingRectangle.Bottom &&
rowElement.ControlBoundingRectangle.Bottom > ViewElement.ScrollableRows.ControlBoundingRectangle.Bottom))
{
if (rowElement.ControlBoundingRectangle.Y < ViewElement.ScrollableRows.ControlBoundingRectangle.Y &&
rowElement.ControlBoundingRectangle.Bottom > ViewElement.ScrollableRows.ControlBoundingRectangle.Y)
{
delta = ViewElement.ScrollableRows.ControlBoundingRectangle.Y - rowElement.ControlBoundingRectangle.Y;
SetScrollValue(this.VScrollBar, this.VScrollBar.Value - delta);
return;
}
if (rowElement.ControlBoundingRectangle.Y < ViewElement.ScrollableRows.ControlBoundingRectangle.Bottom &&
rowElement.ControlBoundingRectangle.Bottom > ViewElement.ScrollableRows.ControlBoundingRectangle.Bottom)
{
delta = rowElement.ControlBoundingRectangle.Top - ViewElement.ScrollableRows.ControlBoundingRectangle.Top;
SetScrollValue(this.VScrollBar, this.VScrollBar.Value + delta);
return;
}
if (ensureVisible)
{
delta = rowElement.ControlBoundingRectangle.Bottom - ViewElement.ScrollableRows.ControlBoundingRectangle.Bottom;
if (delta < 0)
{
break;
}
}
else
{
delta = rowElement.ControlBoundingRectangle.Y - ViewElement.ScrollableRows.ControlBoundingRectangle.Y;
if (delta < 0)
{
delta = 0;
}
}
bool scrollRangeChanged = SetScrollValue(this.VScrollBar, this.VScrollBar.Value + delta);
if (this.VScrollBar.Value >= this.VScrollBar.Maximum - this.VScrollBar.LargeChange + 1 || !scrollRangeChanged)
{
break;
}
}
}
private bool SetScrollValue(RadScrollBarElement scrollbar, int newValue)
{
int max = this.VScrollBar.Maximum;
if (newValue > scrollbar.Maximum - scrollbar.LargeChange + 1)
{
newValue = scrollbar.Maximum - scrollbar.LargeChange + 1;
}
if (newValue < scrollbar.Minimum)
{
newValue = scrollbar.Minimum;
}
scrollbar.Value = newValue;
this.UpdateLayout();
return max != this.VScrollBar.Maximum;
}
}