Home Forums WinForms controls Xceed Grid for WinForms Saving layout of grid Reply To: Saving layout of grid

User (Old forums)
Member
Post count: 23064

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)