I'm trying to make a gridview object dynamic so I don't have to update and distribute a binary every time I want to change the grid construction.
Background:
1) database table with information about reports called GeotechReports
2) database table with information about each field in GeotechReports called GeotechSetup
3) gridview object called GeotechGrid that has AutoGenerateColumns="True"
4) listbox object called GeotechHideColListbox that is bound to GeotechGrid to set the content and state of each listbox member
Information I need from a table, but can't seem to get into the grid or listbox:
1) The GeotechSetup table has two fields of interest: header and visibility. I want to somehow grab the header from this table for the grid to use so the database field name isn't the column header. Since the data is in GeotechReports and the header name is in GeotechSetup (different tables), I don't know how to make the grid understand to look at another datacontext/database table.
2) I want to change the listbox state in the same manner as above. By that I mean I want to set the state based on the visibility field in GeotechSetup.
Here's the relevant xaml:
Essentially what I'm asking is how do I programmatically get access to GeotechGrid and then update each column with the header information stored in GeotechSetup? Here's what I've got so far. I know it accesses the GeotechSetups context as expected from the rlinq object because I displayed x.Fieldname and x.Fieldheader to a message box.
I don't need the communication to be in twoway mode. I'm only interested in doing this to set column default states on first load.
Background:
1) database table with information about reports called GeotechReports
2) database table with information about each field in GeotechReports called GeotechSetup
3) gridview object called GeotechGrid that has AutoGenerateColumns="True"
4) listbox object called GeotechHideColListbox that is bound to GeotechGrid to set the content and state of each listbox member
Information I need from a table, but can't seem to get into the grid or listbox:
1) The GeotechSetup table has two fields of interest: header and visibility. I want to somehow grab the header from this table for the grid to use so the database field name isn't the column header. Since the data is in GeotechReports and the header name is in GeotechSetup (different tables), I don't know how to make the grid understand to look at another datacontext/database table.
2) I want to change the listbox state in the same manner as above. By that I mean I want to set the state based on the visibility field in GeotechSetup.
Here's the relevant xaml:
<
telerik:RadGridView
Grid.Row
=
"1"
Grid.Column
=
"0"
HorizontalAlignment
=
"Stretch"
Margin
=
"0,0,0,0"
CanUserDeleteRows
=
"False"
CanUserInsertRows
=
"False"
IsReadOnly
=
"True"
IsFilteringAllowed
=
"True"
ColumnWidth
=
"*"
SelectionMode
=
"Multiple"
SelectionUnit
=
"FullRow"
AutoGenerateColumns
=
"True"
GroupRenderMode
=
"Flat"
AutoExpandGroups
=
"True"
IsSynchronizedWithCurrentItem
=
"True"
x:Name
=
"GeotechGrid"
ItemsSource
=
"{Binding Path=ReportsToDisplay, Mode=OneWay}"
SelectedItem
=
"{Binding Path=SelectedReport, Mode=TwoWay}"
>
<
telerik:RadGridView.Columns
/>
</
telerik:RadGridView
>
<
ListBox
ItemsSource
=
"{Binding Columns, ElementName=GeotechGrid}"
x:Name
=
"GeotechHideColListbox"
>
<
ListBox.ItemTemplate
>
<
DataTemplate
>
<
CheckBox
Content
=
"{Binding Header}"
IsChecked
=
"{Binding IsVisible, Mode=TwoWay}"
/>
</
DataTemplate
>
</
ListBox.ItemTemplate
>
</
ListBox
>
Essentially what I'm asking is how do I programmatically get access to GeotechGrid and then update each column with the header information stored in GeotechSetup? Here's what I've got so far. I know it accesses the GeotechSetups context as expected from the rlinq object because I displayed x.Fieldname and x.Fieldheader to a message box.
private void RetrieveSetupParameters()
{
foreach(GeotechSetup x in this.context.GeotechSetups.ToList())
{
// 1) x.Fieldname is the name of the field in the GeotechReport table
// 2) x.FieldHeader is what I want to be the column header text
// 3) x.FieldVisibility is what I want to use to set the listbox items
// and hide the columns I specify in the database
}
}
I don't need the communication to be in twoway mode. I'm only interested in doing this to set column default states on first load.