hello,
I am using the xamdatagrid and i was wondering if there was a way to access the column( or field i believe you call it), name and based off that name hide the column. I'm sure its really easy but i cant figure it out for the life of me. here is the code im currently experimenting on:
Imports System.DataImports Infragistics.Windows.DataPresenter
Class Window1 Sub Samp_Loaded(ByVal o As Object, ByVal e As RoutedEventArgs) 'create data using GenerateData Method Dim ds As DataSet = generatedata() 'create an instance of xamdatagrid Dim MyxamDataGrid As New XamDataGrid 'give name MyxamDataGrid.Name = "XamDataGrid1" 'set its datasource property to the default view of 'the dataset created earlier MyxamDataGrid.DataSource = ds.Tables(0).DefaultView
' MyxamDataGrid.DefaultFieldLayout.Visibility = Windows.Visibility.Hidden 'add the newly created xamdatagrid to the grid panel's 'children collection
'If MyxamDataGrid.RecordManager.Field.Name = "Title" Then
MyxamDataGrid.RecordManager.Field.Visibility = Windows.Visibility.Hidden
' End If
MyGrid.Children.Add(MyxamDataGrid) 'find way to make certain column invisible
' ds.Tables("dt").Columns("Title").DefaultValue = Windows.Visibility.Visible = False 'ds.Container.Components.Item(Title).Equals(Visibility = False)
End Sub Function generatedata() As DataSet Dim ds As New DataSet Dim dt As DataTable = ds.Tables.Add("TopMovies")
dt.Columns.Add("Title", GetType([String])) dt.Columns.Add("Running Time", GetType(String)) dt.Columns.Add("MPAA Rating", GetType(String)) dt.Columns.Add("Critics Rating", GetType(String))
dt.Rows.Add(New Object() {"Open Season", "1 hr. 40 min.", "PG", "C"}) dt.Rows.Add(New Object() {"Gridiron Gang", "120 min.", "PG-13", "C+"}) dt.Rows.Add(New Object() {"The Illusionist", "1 hr. 49 min.", _ "PG-13", "B"}) dt.Rows.Add(New Object() _ {"Talladega Nights: The Ballad of Ricky Bobby", "1 hr. 50 min.", _ "PG-13", "B"}) dt.Rows.Add(New Object() _ {"Pirates of the Caribbean: Dead Man's Chest", "145 min.", _ "PG-13", "B-"})
Return ds
End Function
End Class
Thank you in advance
Joel
Hi,
I am currently saving/restoring my own settings file although I use the in built SaveCustomizations as part of my method. Have you tried restoring the settings in grid_Initialized? That's where I've called my method to Load the saved settings. The crux of my load settings method is shown below. Let's know if it works for you.
string filename = ConfigurationManager.AppSettings["settingsFile"];XmlDocument xmldoc = new XmlDocument();xmldoc.Load(filename);XmlNodeList xmlnodes = xmldoc.GetElementsByTagName("fieldLayout")[0].ChildNodes[0].ChildNodes;foreach (XmlNode xmlnode in xmlnodes){ XmlAttributeCollection xmlattrc = xmlnode.Attributes; string name; name = xmlattrc["name"].Value; for (int j = 1; j < xmlattrc.Count; j++) { switch (xmlattrc[j].Name) { case "cellWidth": BQViewGrid.FieldLayouts[0].Fields[name].Settings.CellWidth = double.Parse(xmlattrc[j].Value); break; case "labelWidth": BQViewGrid.FieldLayouts[0].Fields[name].Settings.LabelWidth = double.Parse(xmlattrc[j].Value); break; case "row": BQViewGrid.FieldLayouts[0].Fields[name].Row = int.Parse(xmlattrc[j].Value); break; case "column": BQViewGrid.FieldLayouts[0].Fields[name].Column = int.Parse(xmlattrc[j].Value); break; case "Visibility": BQViewGrid.FieldLayouts[0].Fields[name].Visibility = MyConverterClass.StringToVisibility(xmlattrc[j].Value); break; default: break; } }}
aa_afolabi said: First of all, it does not save the column visibility so if you want to keep that information, you have to manually include it in your 'user.config' file.
First of all, it does not save the column visibility so if you want to keep that information, you have to manually include it in your 'user.config' file.
aa_afolabi said:Loadcustomizations() throws an error if at least one of the fields has all the row and column information and at least one of the other fields does not have it.
I tried saving/restoring my own settings but the restore never had any effect on the layout...I might have been applying the attributes at the wrong time in the code...I tried the in grid_loaded and grid_fieldlayoutinitialized events but that didn't work...or perhaps I was doing it wrong - setting the field. properties. Do you have a code snipped you can share?
Thanks!
I have found that there is a bug with the save/load customizations.
I think you problem results from the fact that when a column is collapsed, 'savecustomizations()' does not save any information for it. Meanwhile if you had moved any columns around before trying to save, all the other columns that are visible would get row, rowspan, column, and columnspan information. Loadcustomizations() throws an error if at least one of the fields has all the row and column information and at least one of the other fields does not have it.
In your case, the fields that where visible before the save have all the information and the ones that where collapsed have no information, hence the error.
I have had to implement my own work around within my project. it involves saving the visibility state of my grid and saving all those row and column information as well for all the collapsed fields. plus a few bits and bobs. Let me know if you need more info.
HI again,
I've encountered another issue with hiding fields/columns by setting visibility=collapsed. If you move the field/column then hide it and then save the settings to the user.config via SaveCustomizations and then reload it you'll get a System.Collections.Generic.KeyNotFoundException - The given key was not present in the dictionary. This error can occur when calling LoadCustomizations or it can occur sometime after the settings are re-loaded. I've been able to reproduce it by hiding a column by setting the field.visibilty = collapsed then moving a column, then saving the settings and closing the dialog When re-opening the dialog and loading the customizations the error occurs. I suspect that the problem is that there are fields/columns being written to the config with no row or column attributes because the field's row = 0 and the column = 0. I'm theorizing here: when the settings are reloaded there are now 2 or more fields that are being set to row 0 col 0: the original field that was there and this "collapsed" one causing a conflict and I suspect one or the other is not being added to the grid. I;ve even tried setting the collapsed fields to visible before saving the settings and tracking them separately but the row/column attributes are still 0,0.
Is there a better way to do this or is there a bug in the grid for the save/load customizations???