OK... I have kindof a sepecialised case. I am getting log data back from a DB that has 5 static properties and then any number of variable properties. The class looks like this:
Prop 1, prop 2, prop 3, collection of properties 4-n... all possible properties are known.
Based on the type of log, properties 4-n will be different, again, all possible properties will be known.
The values of these properties will always be text.
binding properties 1-3 are easy... but is it possible to bind column values to items within a sub collection? for example, key="{Binding PropCollection.Prop4}"
Thanks in advance for any help
Marc
Hi Marc,
If all properties are known, couldn't you create an object that contains properties for all possible properties being sent to the client?
Then when you get the data, loop through the properties and create columns for the props you got back?
If thats not possible, you can explore the options suggested in the following post, using TemplateColumns with DataTemplates built from strings, or creating a custom Column.
http://community.infragistics.com/forums/p/32185/175645.aspx#175645
-SteveZ
Yes... but that would be the easy way out and we wouldnt be programming Micrrosoft products if we settled for that... ;)
no, actually, I have about a dozen types of logs that contain the same core data, but each log has different sets of property data that would be within the collection. I would like to avoid defining on specific class for each of the log types. What I would like to do is have a generic class that contains the core data and then a collection of log entry proprties for the variable stuff. The collection would contain the property name, ID and value. When I get my log back I want to create the columns for that log type dynamically, then as I'm populating my rows, assign them to the specific properties within the sub collection.
I can consistently make the grid crash using the Unbound columns only (about 10 of them) with teh following steps:
Drag Column 3 to Group by by area, Expand first row in list, drag column 4 to group by area.
Then drag Column 3 from the group by area back onto the grid. I get the above "object not set to instance" error every time. I will continue to test.
Should the following scenerio work with a Unbound Column:
I am trying to render a Image in a column based on the Url in the dictionary. the converter runs and returns the correct BitMapImage, but it does not display in the grid. if i change the image width and height in my custom datatemplate the grid expands so i think the itemtemplate is working correctly
Set the datatemplate of the column to:
<
DataTemplate x:Key="iconPresenterStyle"> <
Image Stretch="Fill" Width="40" Height="40" Source="{Binding}" /> </
</
DataTemplate>
Code is here:
if (IsIcon) { ItemTemplate = Application.Current.Resources["iconPresenterStyle"] as DataTemplate; // Gets absolute url based on location of .xap download converter = new Hyland.Types.Silverlight.Converters.IconUriConverter(); ValueConverterParameter = Convert.ToString(columnElement["name"]); }
if
(IsIcon) { ItemTemplate =
{
ItemTemplate =
Application.Current.Resources["iconPresenterStyle"] as DataTemplate;
// Gets absolute url based on location of .xap download
converter =
new Hyland.Types.Silverlight.Converters.IconUriConverter(); ValueConverterParameter =
ValueConverterParameter =
Convert.ToString(columnElement["name"]); }
}
Converter is here:
PropertyBag bag = value as PropertyBag; string index = parameter as string; Uri uri = null; if (null != bag && !string.IsNullOrEmpty(index)) { if (bag.Contains(index)) { // ../ assumes the Xap package is in a clientbin folder below the root uri = new Uri(Application.Current.Host.Source, "../" + bag[index]); } } // return image from onbase web server or an empty image if no // url found in element if (null != uri) { return new BitmapImage(uri); } else { return new BitmapImage(); }
PropertyBag
bag = value as PropertyBag;
string index = parameter as string;
Uri uri = null;
if (null != bag && !string.IsNullOrEmpty(index)) {
if (bag.Contains(index)) {
// ../ assumes the Xap package is in a clientbin folder below the root
uri =
new Uri(Application.Current.Host.Source, "../" + bag[index]); } }
// return image from onbase web server or an empty image if no
// url found in element
if (null != uri) {
return new BitmapImage(uri); }
else
return new BitmapImage(); }
Hi Ted,
Sorry for the delayed response.
I should have mentioned this earlier. The UnboundColumn has a different DataContext than a TemplateColumn. We did this, so that users have access to more information, and also so they don't have to duplicate their work.
So the DataContext is of type: UnboundColumnDataContext, which as 3 members that you can bind to:
RowData, Value, and ColumnKey.
RowData - represents the data object for the current row.
ColumnKey - is simply the key that you assigned to the column
Value - is what your ValueConverter returns.
So, in the DataTemplate you listed above you should use {Binding Value}
Hope this helps,
could you explain this line a little further.
elem.DataContext = mdo.Properties[cell.Column.Key];
i am trying to reproduce in vb.net...
is it possible to use this set up to Edit the columns you generate on the fly?
i have a collection that has a parent / child row set up in it. i have got it to create and bind the columns based on the data that i have in the child collection.
here is the error it is throwing, the numbers are different based on the cell and row
Invalid Binding Path; character 3 in 3.
at System.Windows.PropertyPathParser.ReadStepDescriptor(Boolean calledFromParser) at System.Windows.PropertyPathParser.Parse() at System.Windows.PropertyPath.ParsePath(String path, Boolean calledFromParser) at System.Windows.PropertyPath.ParsePathInternal(Boolean calledFromParser) at System.Windows.Data.Binding.set_Path(PropertyPath value) at System.Windows.Data.Binding..ctor(String path) at Infragistics.Silverlight.Controls.Primitives.ColumnContentProviderBase.ResolveEditorBinding(Cell cell) at Infragistics.Silverlight.Controls.CellControl.AddEditorToControl() at Infragistics.Silverlight.Controls.Cell.EnterEditMode(Boolean cellIsEditing) at Infragistics.Silverlight.Controls.XamWebGrid.EnterEditModeInternal(Row row, Cell cell) at Infragistics.Silverlight.Controls.XamWebGrid.EnterEditMode(CellBase cell) at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection, Boolean setFocus, Boolean scrollIntoView) at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection, Boolean scrollIntoView) at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection) at Infragistics.Silverlight.Controls.Cell.OnCellMouseDown(MouseEventArgs e) at Infragistics.Silverlight.Controls.XamWebGrid.c(Object A_0, MouseButtonEventArgs A_1) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Hi,
So, what exactly are you doing?
Can you explain your scenario? Are you creating a Custom ColumnContentProvider?
What does your editing template look like?
The more information you provide, the better chance we have of helping you.
Thanks,
I am basically trying to reproduce the sample you suplied on the first page but with slightly different requirements
i am going to have a parent / child class set up. i would like the rows in the child collection to end up being the dynamic columns
i was able to get this 'working' in a view only set up. i need to allow the users to able to edit these dynamic columns
i will post the code i am using ion the next post.
If this is refering to my Unbound column issues, i have not experienced this since moving to the release version of 2010.1 Unbound Columns
once my solution built on this goes to QA if they find issues I may ask again in a new thread, but for now i am good to go.
thanks.
KEEP IN MIND THIS IS ALL TEST CODE''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Structure TwoInts
Private _int1 As Integer Private _int2 As Integer Private _int3 As Integer
Public Property Int1() As Integer Get Return Me._int1 End Get Set(ByVal value As Integer) Me._int1 = value End Set End Property
Public Property Int2() As Integer Get Return Me._int2 End Get Set(ByVal value As Integer) Me._int2 = value End Set End Property
Public Property Parent() As Integer Get Return Me._int3 End Get Set(ByVal value As Integer) Me._int3 = value End Set End Property
Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean If obj Is Nothing Then Return False End If Return Me.Int1 = DirectCast(obj, TwoInts).Int1 End FunctionEnd Structure'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Class testList
Private _str As String
Property Str() As String Get Return _str End Get Set(ByVal value As String) _str = value End Set End Property
Private _lst As List(Of TwoInts) Property ListInts() As List(Of TwoInts) Get Return _lst End Get Set(ByVal value As List(Of TwoInts)) _lst = value End Set End PropertyEnd Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Imports Infragistics.Silverlight.ControlsImports Infragistics.Silverlight.Controls.PrimitivesImports System.Windows.Data
Public Class MyColumn Inherits TemplateColumn
Protected Overloads Overrides Function GenerateContentProvider() As ColumnContentProviderBase
Return New MyColumnContentProvider() End Function
End Class
Public Class MyColumnContentProvider Inherits TemplateColumnContentProvider
Public Overloads Overrides Function ResolveDisplayElement(ByVal cell As Cell, _ ByVal cellBinding As Binding) _ As FrameworkElement
Dim elem As FrameworkElement = MyBase.ResolveDisplayElement(cell, cellBinding)
If elem IsNot Nothing Then
Dim mdo As testList = TryCast(cell.Row.Data, testList)
If mdo IsNot Nothing Then
Dim qry = From p In mdo.ListInts Where p.Int1 = cell.Column.Key Select p '(From p In mdo.ListInts Where p.Int1 = cell.Column.Key Select p).Count() > 1 If qry.Count() > 0 Then
elem.DataContext = (From p In mdo.ListInts _ Where p.Int1 = cell.Column.Key Select p).SingleOrDefault()
'mdo.ListInts(cell.Column.Key) Else elem.DataContext = Nothing End If
'mdo.ListInts.GetType.GetProperties(0) '.GetType.GetProperties(0) '.GetType.GetProperties(cell.Column.Key) 'mdo.GetType.FindMembers(Reflection.MemberTypes.Property, cell.Column.Key) End If End If
Return elem End Function
Protected Overloads Overrides Function ResolveEditorControl(ByVal cell As Cell, _ ByVal editorValue As Object, _ ByVal availableWidth As Double, _ ByVal availableHeight As Double, _ ByVal editorBinding As Binding) _ As System.Windows.FrameworkElement
Dim editor As FrameworkElement = MyBase.ResolveEditorControl(cell, editorValue, _ availableWidth, _ availableHeight, _ editorBinding)
If editor IsNot Nothing Then
Dim qry = From p In mdo.ListInts Where p.Int1 = cell.Column.Key Select p
If qry.Count() > 0 Then
editor.DataContext = (From p In mdo.ListInts _ Where p.Int1 = cell.Column.Key Select p).SingleOrDefault()
'mdo.ListInts(cell.Column.Key) Else editor.DataContext = Nothing End If End If End If
Return editor
'Return MyBase.ResolveEditorControl(cell, editorValue, availableWidth, availableHeight, editorBinding) End FunctionEnd Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Generate data and columns in test page loaded event'''''''''''''' Dim li As New List(Of TwoInts) Dim li2 As New List(Of TwoInts) Dim li3 As New List(Of TwoInts) Dim li4 As New List(Of TwoInts)
Dim l As New List(Of testList) Dim val2 As Integer = 100
For x As Integer = 0 To 5
li.Add(New TwoInts() With {.Int1 = x, .Int2 = 111}) 'val2 += 1 Next
For x As Integer = 6 To 8
li2.Add(New TwoInts() With {.Int1 = x, .Int2 = 222}) Next
For x As Integer = 3 To 9
li3.Add(New TwoInts() With {.Int1 = x, .Int2 = 333}) Next
For x As Integer = 9 To 13
li4.Add(New TwoInts() With {.Int1 = x, .Int2 = 444}) Next
l.Add(New testList() With {.Str = "Row One", .ListInts = li}) l.Add(New testList() With {.Str = "Row Two", .ListInts = li2}) l.Add(New testList() With {.Str = "Row Three", .ListInts = li3}) l.Add(New testList() With {.Str = "Row Four", .ListInts = li4})
Dim template As DataTemplate = LayoutRoot.Resources("colTemplate") Dim editTemplate As DataTemplate = LayoutRoot.Resources("colTemplateEdit")
For Each y In li
If dg.Columns.Item(y.Int1.ToString()) Is Nothing Then
dg.Columns.Add(New MyColumn() With {.Key = y.Int1, _ .ItemTemplate = template, _ .EditorTemplate = editTemplate, _ .Width = New ColumnWidth(35, False)}) End If Next
For Each y In li2
For Each y In li3
For Each y In li4
dg.ItemsSource = l
''''''''''''''''''''''''''''''''''''''''''''''''''
<DataTemplate x:Key="colTemplate">
<TextBlock Text="{Binding Int2}"></TextBlock>
</DataTemplate> <DataTemplate x:Key="colTemplateEdit">
<TextBox Text="{Binding Int2}" TextAlignment="Right"></TextBox>
</DataTemplate>
'''''''''''''''''''''''''''''''''' <igGrid:XamWebGrid x:Name="dg" Margin="10" AutoGenerateColumns="False" Background="Transparent" VerticalAlignment="Top" Grid.Row="1" Grid.Column="0">
<igGrid:XamWebGrid.Columns>
<igGrid:TextColumn Key="Str" Width="75" /> </igGrid:XamWebGrid.Columns>
<igGrid:XamWebGrid.EditingSettings> <igGrid:EditingSettings AllowEditing="Cell" IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="true" /> </igGrid:XamWebGrid.EditingSettings> </igGrid:XamWebGrid>
i am not sure what you are refering to?
as for as going to 2010.1 i am not sure i am permitted to do that yet, got to get the bosses approval for that.
if that would be a better solutions, please share