Thursday, May 9, 2013
Get Data Grid Column Binding List
private void GetShowColumnList()
{
ShowColumnNames = "";
ShowColumnAttributeList = new Dictionary<string, string>();
if (PersonalizeColumnGrid.ItemsSource != null)
{
foreach (var objCol in PersonalizeColumnGrid.ItemsSource)
{
if (((dynamic)objCol).IsSelected)
{
string headerName = ((dynamic)objCol).Column;
//ShowColumnNames = ShowColumnNames + headerName + ",";
foreach (var objGridAttribute in suppliedDataGrid.Columns)
{
if (objGridAttribute.ClipboardContentBinding != null)
{
if (objGridAttribute.Header != null)
{
if (headerName == objGridAttribute.Header.ToString())
{
string colAttribute = objGridAttribute.ClipboardContentBinding.Path.Path;
ShowColumnAttributeList.Add(colAttribute, headerName);
break;
}
}
}
// if( ((dynamic)objCol).Column
}
}
}
//ShowColumnNames = ShowColumnNames.Substring(0, ShowColumnNames.Length - 1);
ShowColumnNames = Extension.ConvertDictinaryToString(ShowColumnAttributeList);
}
//get
public static string ConvertDictinaryToString<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
{
//return string.Join(",", dictionary.Select(kv => kv.Key.ToString() + "{" + kv.Value.ToString()).ToArray()).Replace(' ', '~'); ;
return string.Join(",", dictionary.Select(kv => kv.Key.ToString().Trim()+"*" + kv.Value.ToString().Trim()).ToArray()).Replace(' ', '~');
}
//back
private void ConvertStringToDictionary(string ColumnList)
{
try
{
if (!string.IsNullOrEmpty(ColumnList))
{
ColumnList = ColumnList.Replace('~', ' ');
List<string> colList = ColumnList.Split(',').ToList<string>();
foreach (string colItem in colList)
{
if (colItem.Contains('*'))
{
reportColumnList.Add(colItem.Split('*')[0].ToString(), colItem.Split('*')[1].ToString());
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
Labels:
Silverlight
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment