Home › Forums › WinForms controls › Xceed Grid for WinForms › Saving layout of grid
-
AuthorPosts
-
#12875 |
How to save layout of grid 2.0.
Is this posible. I have found function Save but
I don’t know how to use it.Imported from legacy forums. Posted by konrad (had 5623 views)
Hello,
The Save method of the StyleSheet class is used to save the appearance of the grid. It cannot be used to save the grid’s layout.
Unfortunately, there is no built-in function to save the grid’s layout.
Imported from legacy forums. Posted by Jenny [Xceed] (had 395 views)
konrad007:
Is it the column’s Width, Visible, SortDirection and VisibleIndex that you want to save?
Imported from legacy forums. Posted by C# (had 404 views)
Yes, exactly this and columns sequence
Imported from legacy forums. Posted by konrad (had 311 views)
Well, I also need this function on the grid.
As now I use this method to retrive these settings:
public string _getAllColumnSettings()
{
System.Text.StringBuilder res = new System.Text.StringBuilder();try
{
//************
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
res.Append(col.FieldName + “*” + col.Visible + “*”);
}//************
res.Append(“#”);
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
res.Append(col.FieldName + “*” + col.Width + “*”);
}
//***************
res.Append(“#”);
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
res.Append(col.FieldName + “*” + col.SortDirection + “*”);
}
//***************
res.Append(“#”);
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
res.Append(col.FieldName + “*” + col.VisibleIndex + “*”);
}}
catch (Exception ex)
{
throw new Exception(ex.StackTrace);
}
return str;
}This method returns one very very long string, that represent the grid’s layout
Imported from legacy forums. Posted by C# (had 340 views)
And I use this method to apply these settings to the grid again:
public void _setAllGridSettings(string allColSettings)
{
try
{
string temp = allColSettings;
if (allColSettings != null)
{Hashtable VisibleHT = new Hashtable();
Hashtable WidthHT = new Hashtable();
Hashtable SortDirectionHT = new Hashtable();
Hashtable VisibleIndexHT = new Hashtable();Regex r = new Regex(“#”);
string [] splitSettings = r.Split(temp);//*********************************VisibleHT********************************
string VisibleStr = splitSettings[0];if (VisibleStr.EndsWith(“*”))
{
VisibleStr = VisibleStr.Remove(VisibleStr.Length-1,1);
}r = new Regex(“#”);
string newVisibleStr = VisibleStr.Replace(“*”,”#”);string [] visibleSplit = r.Split(newVisibleStr);
for (int i = 0; i<visibleSplit.Length/2; i++)
{
VisibleHT.Add(visibleSplit[2*i], visibleSplit[2*i+1]);
}
//************************************************************************//*********************************WidthHT********************************
string WidthStr = splitSettings[1];
if (WidthStr.EndsWith(“*”))
{
WidthStr = WidthStr.Remove(WidthStr.Length-1,1);
}r = new Regex(“#”);
string newWidthStr = WidthStr.Replace(“*”,”#”);string [] widthSplit = r.Split(newWidthStr);
for (int i = 0; i<widthSplit.Length/2; i++)
{
WidthHT.Add(widthSplit[2*i], widthSplit[2*i+1]);
}//************************************************************************
//*********************************SortDirectionHT************************
string SortDirectionStr = splitSettings[2];
if (SortDirectionStr.EndsWith(“*”))
{
SortDirectionStr = SortDirectionStr.Remove(SortDirectionStr.Length-1,1);
}r = new Regex(“#”);
string newSortDirectionStr = SortDirectionStr.Replace(“*”,”#”);string [] sortDirectionSplit = r.Split(newSortDirectionStr);
for (int i = 0; i<sortDirectionSplit.Length/2; i++)
{
SortDirectionHT.Add(sortDirectionSplit[2*i], sortDirectionSplit[2*i+1]);
}//************************************************************************
//*********************************VisibleIndexHT*************************
string VisibleIndexStr = splitSettings[3];
if (VisibleIndexStr.EndsWith(“*”))
{
VisibleIndexStr = VisibleIndexStr.Remove(VisibleIndexStr.Length-1,1);
}r = new Regex(“#”);
string newVisibleIndexStr = VisibleIndexStr.Replace(“*”,”#”);string [] visibleIndexSplit = r.Split(newVisibleIndexStr);
for (int i = 0; i<visibleIndexSplit.Length/2; i++)
{
VisibleIndexHT.Add(visibleIndexSplit[2*i], visibleIndexSplit[2*i+1]);
}//************************************************************************
this.setColumnVisible(VisibleHT);
this.setColumnWidth(WidthHT);
this.setColumnSort(SortDirectionHT);
this.setColumnOrder(VisibleIndexHT);}
}
catch (Exception ex)
{
//throw new Exception(ex.StackTrace);
}
}private void setColumnOrder(Hashtable hash)
{
try
{
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
if (hash.Contains(col.FieldName))
{
col.VisibleIndex = Int32.Parse((string)hash[col.FieldName]);
}
}
}
catch (Exception ex)
{
throw new Exception(ex.StackTrace);
}
}private void setColumnWidth(Hashtable hash)
{
try
{
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{
if (hash.Contains(col.FieldName))
{
col.Width = Int32.Parse((string)hash[col.FieldName]);
}
}
}
catch (Exception ex)
{
throw new Exception(ex.StackTrace);
}
}private void setColumnSort(Hashtable hash)
{
try
{
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{if ( (string)hash[col.FieldName] == “None”)
{
col.SortDirection = Xceed.Grid.SortDirection.None;
}
else if ( (string)hash[col.FieldName] == “Ascending”)
{
col.SortDirection = Xceed.Grid.SortDirection.Ascending;
}
else if ( (string)hash[col.FieldName] == “Descending”)
{
col.SortDirection = Xceed.Grid.SortDirection.Descending;
}
}
}
catch (Exception ex)
{
throw new Exception(ex.StackTrace);
}
}private void setColumnVisible(Hashtable hash)
{try
{
foreach (Xceed.Grid.Column col in this.gridControl1.Columns)
{if (hash.Contains(col.FieldName))
{
if ( (string)hash[col.FieldName] == “True”)
{
col.Visible = true;
}else if (
Imported from legacy forums. Posted by C# (had 446 views)
Notice that if you have a grid with 20 column, then the string will be about 2000 character long.
Imported from legacy forums. Posted by C# (had 240 views)
Notice that I have only testet the 2 methods with Grid v.1.1.
So it will properly not work with Master/detail and with groups.
Imported from legacy forums. Posted by C# (had 6857 views)
-
AuthorPosts
- You must be logged in to reply to this topic.