Home Forums WPF controls Xceed DataGrid for WPF Hiding a Column in master / detail

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26303 |

    I would like to hide a column in one of the detail views but I keep getting a exception.
    The code I am trying to do that with is below….perhaps I am going about this the wrong way?

    table_Site_ID.ChildRelations.Add(new DataRelation(“Site_Contacts”, table_Site_ID.Columns[“ID”], table_Site_Contacts.Columns[“Site_ID”]));

    table_Site_ID.ChildRelations.Add(new DataRelation(“Scheduler”, table_Site_ID.Columns[“ID”], table_Scheduler.Columns[“ID”]));

    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView(table_Site_ID.DefaultView);
    dataGridControl_Site_ID.ItemsSource = dataGridCollectionView;

    dataGridControl_Site_ID.DetailConfigurations[“Site_Contacts”].Columns[“Contact_ID”].Visible = false;

    Without the last line of code there….the detail is displayed properly.
    But as soon as I add the last code line I get the exception that I list below.


    Also is there a property or some easier way to not show the header columns when a detail is empty? I am looking at the Master/Detail example that is included and am getting a bit confused as to what is goin on there. I don’t want to give the user the ability to toggle that on and off. I just want it off.

    Here is the exception:

    System.Windows.Markup.XamlParseException was unhandled
    Message=”Cannot create instance of ‘Window1’ defined in assembly ‘iGlimpse2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation. Error in markup file ‘Window1.xaml’ Line 2 Position 2.”
    Source=”PresentationFramework”
    LineNumber=2
    LinePosition=2
    StackTrace:
    at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
    at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
    at System.Windows.Markup.BamlRecordReader.ThrowException(String message, Exception innerException)
    at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
    at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
    at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
    at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
    at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
    at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
    at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
    at System.Windows.Markup.TreeBuilder.Parse()
    at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
    at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
    at MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
    at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
    at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
    at System.Windows.Navigation.NavigationService.DoNavigate(Uri source, NavigationMode f, Object navState)
    at System.Windows.Navigation.NavigateQueueItem.Dispatch(Object obj)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Threading.DispatcherOperation.Invoke()
    at System.Windows.Threading.Dispatcher.ProcessQueue()
    at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
    at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
    at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
    at System.Windows.Threading.Dispatcher.Run()
    at System.Windows.Application.RunInternal(Window window)
    at System.Windows.Application.Run(Window window)
    at System.Windows.Application.Run()
    at iGlimpse2.App.Main() in C:\expression\projects\iGlimpse2\obj\Debug\App.g.cs:line 0
    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.

    Imported from legacy forums. Posted by David (had 2476 views)

    Xceed Support
    Member
    Post count: 5658

    Columns in details are detected/created only when the first detail is expanded.

    Therefore, trying to access the “Contact_ID” column from the “newly” created detail configuration is bound to generate a NullReferenceException, which is then trapped by the XamlParser (hence the XamlParseException ).

    The workaround to this would be to create and add a “Contact_ID” column to the DetailConfiguration before invoking the last line, and then everything should be fine.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 602 views)

    User (Old forums)
    Member
    Post count: 23064

    Ahh well that clears a bunch of things up.

    So adding that and hiding it before it is created won’t have any ill effects?

    If I add this line of code before trying to hide it will work? dataGridControl_Site_ID.DetailConfigurations[“Site_Contacts”].Columns.Add(?);

    Also how do you go about converting a DataTable (table_Site_Contacts.Columns[“Contact_ID”]) to a WPF.DataGrid.Column?

    Imported from legacy forums. Posted by David (had 3632 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.