| using System; |
| using System.Collections; |
| using System.IO; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Telerik.Web.UI; |
| namespace WebApplication1 |
| { |
| public class GridSettingsPersister |
| { |
| private RadGrid gridInstance; |
| public GridSettingsPersister( RadGrid gridInstance ) |
| { |
| this.gridInstance = gridInstance; |
| } |
| //this method should be called on Render |
| public string SaveSettings() |
| { |
| object[] gridSettings = new object[4]; |
| //Save groupBy |
| GridGroupByExpressionCollection groupByExpressions = gridInstance.MasterTableView.GroupByExpressions; |
| object[] groupExpressions = new object[groupByExpressions.Count]; |
| int count = 0; |
| foreach( GridGroupByExpression expression in groupByExpressions ) |
| { |
| groupExpressions[count] = ((IStateManager)expression).SaveViewState(); |
| count++; |
| } |
| gridSettings[0] = groupExpressions; |
| //Save sort expressions |
| gridSettings[1] = ((IStateManager)gridInstance.MasterTableView.SortExpressions).SaveViewState(); |
| //Save columns order |
| int columnsLength = gridInstance.MasterTableView.Columns.Count + |
| gridInstance.MasterTableView.AutoGeneratedColumns.Length; |
| Pair [] columnOrder = new Pair[ columnsLength ]; |
| ArrayList allColumns = new ArrayList( columnsLength ); |
| allColumns.AddRange(gridInstance.MasterTableView.Columns ); |
| allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns); |
| int i = 0; |
| foreach( GridColumn column in allColumns ) |
| { |
| Pair p = new Pair(); |
| p.First = column.OrderIndex; |
| p.Second = column.HeaderStyle.Width; |
| columnOrder[i] = p; |
| i++; |
| } |
| gridSettings[2] = columnOrder; |
| //Save filter expression |
| gridSettings[3] = (object)gridInstance.MasterTableView.FilterExpression; |
| LosFormatter formatter = new LosFormatter(); |
| StringWriter writer = new StringWriter(); |
| formatter.Serialize( writer, gridSettings ); |
| return writer.ToString(); |
| } |
| //this method should be called on PageInit |
| public void LoadSettings( string settings ) |
| { |
| LosFormatter formatter = new LosFormatter(); |
| StringReader reader = new StringReader( settings ); |
| object[] gridSettings = (object[])formatter.Deserialize( reader ); |
| //Load groupBy |
| GridGroupByExpressionCollection groupByExpressions = this.gridInstance.MasterTableView.GroupByExpressions; |
| groupByExpressions.Clear(); |
| object[] groupExpressionsState = (object[])gridSettings[0]; |
| int count = 0; |
| foreach( object obj in groupExpressionsState ) |
| { |
| GridGroupByExpression expression = new GridGroupByExpression(); |
| ((IStateManager)expression).LoadViewState( obj ); |
| groupByExpressions.Add( expression ); |
| count++; |
| } |
| //Load sort expressions |
| this.gridInstance.MasterTableView.SortExpressions.Clear(); |
| ((IStateManager)this.gridInstance.MasterTableView.SortExpressions).LoadViewState( gridSettings[1] ); |
| //Load columns order |
| int columnsLength = this.gridInstance.MasterTableView.Columns.Count + |
| this.gridInstance.MasterTableView.AutoGeneratedColumns.Length; |
| Pair [] columnOrder = (Pair[])gridSettings[2]; |
| if ( columnsLength == columnOrder.Length) |
| { |
| ArrayList allColumns = new ArrayList( columnsLength ); |
| allColumns.AddRange(this.gridInstance.MasterTableView.Columns ); |
| allColumns.AddRange(this.gridInstance.MasterTableView.AutoGeneratedColumns); |
| int i = 0; |
| foreach( GridColumn column in allColumns ) |
| { |
| column.OrderIndex = (int)columnOrder[i].First; |
| column.HeaderStyle.Width = (Unit)columnOrder[i].Second; |
| i++; |
| } |
| } |
| //Load filter expression |
| this.gridInstance.MasterTableView.FilterExpression = (string)gridSettings[3]; |
| } |
| } |
Hi,
Is it possible to custom the context menu on grid header?
In particular, I want to add a menu item for grouping my grid on one of the columns. That is the only one column my users are likely to group the grid, so I don't want to show the whole group panel.
I may want to add some anther menu items too.
Thanks.
If you go Edit UI and change the column header bgcolor it breaks the grid (invalid index)
It puts this in the designer code:
CType
(Me.radDataList.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(0), Telerik.WinControls.UI.GridHeaderCellElement).BackColor2 = System.Drawing.Color.FromArgb(CType(CType(232, Byte), Integer), CType(CType(241, Byte), Integer), CType(CType(251, Byte), Integer))
I would use the theme builder but it is barely working now (2009), wont let me change images on anything (button doesn't work) have to add it to the xml file instead, and the theme builder doesn't do any changes to headers even if i change the XML file
IE:
<XmlPropertySettingGroup>
<PropertySettings>
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.GradientStyle" Value="Linear" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.GradientAngle" Value="90" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.GradientPercentage" Value="0.3152455" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.GradientPercentage2" Value="0.3333333" />
<XmlPropertySetting Property="Telerik.WinControls.VisualElement.BackColor" Value="243, 242, 237" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.BackColor2" Value="243, 242, 237" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.BackColor3" Value="243, 242, 237" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.BackColor4" Value="243, 242, 237" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.NumberOfColors" Value="4" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.DrawFill" Value="True" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.BorderColor" Value="222, 215, 222" />
<XmlPropertySetting Property="Telerik.WinControls.VisualElement.SmoothingMode" Value="AntiAlias" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.DrawBorder" Value="True" />
<XmlPropertySetting Property="Telerik.WinControls.UI.LightVisualElement.BorderGradientStyle" Value="Solid" />
<XmlPropertySetting Property="Telerik.WinControls.VisualElement.ForeColor" Value="103, 167, 227" />
</PropertySettings>
<Selectors>
<XmlClassSelector ElementClass="HeaderCell" />
</Selectors>
</XmlPropertySettingGroup>
Any thoughts?