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.
firstly, i have my cake and i can eat it too! the Unbound column is exactly what i was looking for.
i do randomly get the following error, but it's beta right! when will it be released?
Unhandled Error in Silverlight Application Object reference not set to an instance of an object. at Infragistics.Silverlight.Controls.RowBase.get_Columns()\n at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection, Boolean setFocus, Boolean scrollIntoView)\n at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection, Boolean scrollIntoView)\n at Infragistics.Silverlight.Controls.XamWebGrid.SetActiveCell(CellBase cell, CellAlignment alignment, InvokeAction action, Boolean allowSelection)\n at Infragistics.Silverlight.Controls.Cell.OnCellMouseDown(MouseEventArgs e)\n at Infragistics.Silverlight.Controls.XamWebGrid.c(Object A_0, MouseButtonEventArgs A_1)\n at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName
Hey Ted,
Glad this is what you're looking for.
Do you have a sample, and some steps to reproduce?
This will help ensure that the issue is definitely fixed for the release.
Thanks,
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"]);
}
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();
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,
IG
any idea whats wrong with my sample or why that Silverlight is throwing that exception that i posted at the top of page 3, (when you click on one of the cells)????
yeah at the moment i am using this and it seems to work
Private Function CreateXamTemplateColumn(ByVal i As Integer, _ ByVal propName As String) As ColumnBase
Dim column As New TemplateColumn()
column.Key = propName & i
column.HeaderText = String.Format("Period#{0}.{1}", i, propName)
column.ItemTemplate = XamlReader.Load(CreateColumnTemplate(i, propName))
column.EditorTemplate = XamlReader.Load(CreateColumnEditTemplate(i, propName)) ' //edit template Return column End Function
Also, generate a unique key for each colum:
column.Key = propName //******* Generate Unqiue key **************// string.format("Column{0}", i); or something like that. Maybe use a random number or somehting, just make it unique.
make sure you are not concatenating anything to the propName parameter. Actually just remove it all together, and replace the {1} in the string.format method with the Hours property. Do this with both the item template and edit template methods.
Private Function CreateColumnEditTemplate(ByVal index As Integer) As String
Dim CellTemp As New StringBuilder() CellTemp.Append("<DataTemplate ") CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/") CellTemp.Append("2006/xaml/presentation' ") CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>") CellTemp.Append([String].Format("<TextBox Text='{{Binding Periods[{0}].Hours, Mode=TwoWay}}' TextAlignment='Right'/>", _ index, propertyName)) CellTemp.Append("</DataTemplate>")
Return CellTemp.ToString() End Function
so i guess based on what you were said earlier about them throwing an error, was it possibly the dup key i error.
i added the index to "hours" to change the key so i would not throw that exception
i changed it back to test, and just exited the loop after one and it seems to work.
anythoughts on how to get around this
ALSO, thanks for all the help!