Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF Controls DataGrid
I'm writing my first WPF application. The main window has a datagrid that is bound to a datatable that that contains all but one field from the datasource. The remaining field from the datasource contains one or more of the following: txt, html, or rtf. The format of the data in this field is like so:
 
<!txt!>   <--indicates type of data that follows
<*filename*> <-- name of the file this data came from.
text data
<!rtf!>
<*filename*>
rtf data
<!html!>
<*filename*>
html data
 
When a row is selected, a RowDetails panel is shown with a TabControl. Here's where my question comes in.
 
Upon the row selection, I'd like to query the datasource for this field and for each data type indicator found in the data, create a Tab in the TabControl with the appropriate viewer (TextBox, RichTextBox, or WebBrowser) as the Tab's child and the Tab Header as the filename.
 
I'm looking for guidance. Is this possible with Xaml & converters or controllers? I've read several articles but have been unable to devise a way to implement my particular need. Or maybe this could be done strictly with code but I've not been successful accessing the tab control in the RowDetails panel.
 
Hoping someone can get me pointed in the right direction.
Posted 10-Sep-11 11:53am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Create a property in the CodeBehind or ViewModel. Use that property and create a Binding to the DataGrid's SelectedItem (you have probably done this already).
 
Then the SelectedItem property should hold a row as defined in the ItemsSource.
If the rows are known classes with known properties, this is simple. If it's a DataTable with DataRows, it's still quite possible but maybe a little more hazzle.
 
In the TabControl, create a Binding to the "ItemsSource" (for the TabControl) to the SelectedItem. Then use a Converter with a StaticBinding to a class implementing the "IValueConverter".
 
The "value" property in the converter's "Convert" method should then be a the SelectedItem.
 
Parse the SelectedItem properties or columns, create an ObservableCollection<Control> or ObservableCollection<TabItem>. If you create a collection of Control, you may have to define an "ItemTemplate" for the TabControl.
 
Then add all the controls you need to the colelction and return the whole collection in the converter's "Convert" method.
 
I hope I understood the problem/question Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Afzaal Ahmad Zeeshan 82
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 14 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100