|
Hi,
I'm trying to bind my ICollectionView data to a DataGrid and am not getting any data displayed, even though the data is retrieved from my data source.
I am trying to populate my DataGrid with data received as the result of a Button press, and can only assume that the problem is that my ICollectionView data is received on a separate thread. The data is received correctly, and my list is populated fully, but just not displayed.
My XAML is this
<Window x:Class="UPC_Programmer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UPCP="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:GridLines="clr-namespace:UPC_Programmer" Closing="Window_OnClosing"
xmlns:tree="clr-namespace:Aga.Controls.Tree;assembly=Aga.Controls"
x:Name="DataTree"
<ToolBarPanel Height="26" HorizontalAlignment="Stretch" Margin="1,22,0,4"
Name="toolBarPanel1" VerticalAlignment="Stretch" Width="800" Orientation="Horizontal"
Background="Gray" Grid.ColumnSpan="4">
<Button x:Name="Controller_Read" Height="25" Width="50" Click="OnReadBtnClk"
IsEnabled="False">
</Button>
</ToolBarPanel>
<DockPanel Height="448" Width="801" Grid.ColumnSpan="4"
Margin="0,51,0,29" Grid.RowSpan="2">
<UPCP:DataGrid DataContext="{StaticResource GroupedCustomers}" ItemsSource="{Binding}"
AutoGenerateColumns="False" Grid.Row="1" Height="447" HorizontalAlignment="Left"
Name="dataGrid2" VerticalAlignment="Top" Width="799" Grid.ColumnSpan="4">
<UPCP:DataGrid.Columns>
<UPCP:DataGridTextColumn Header="Parameter" Width="400"
Binding="{Binding Path=TagName}" Foreground="Black"/>
<UPCP:DataGridTextColumn Header="Value" Width="50"
Binding="{Binding Path=Value}" Foreground="Black"/>
<UPCP:DataGridTextColumn Header="" Width="50"
Binding="{Binding Path=Value3}" Foreground="Black"/>
</UPCP:DataGrid.Columns>
</UPCP:DataGrid>
</DockPanel>
</Window>
And my Code Behind is similar to that below
public partial class MyClass
{
public ICollectionView GroupedCustomers { get; private set; }
private MY_LIST<MY_VALUES> currentValueList = null;
private void OnReadBtnClk(object sender, RoutedEventArgs e)
{
RequestService(LIBRARY.LIB.OFFERED_SERVICES.GET_CURRENT_VALUES);
}
void OnValueListReceived(object sender, ValueListConnectionHandlerEventArgs e)
{
if (e.GetValueList.List != null)
{
this.currentValueList = e.GetValueList;
if (this.currentValueList.Count() > 0)
{
LoadData();
}
}
}
private void LoadData()
{
_TagCollection.Clear();
foreach(VALUES item in currentValueList)
{
try
{
if (item.GetValueType == TYPE_INT)
{
MemoryStream ms = item.GetValueStreamed;
BinaryFormatter bFormatter = new BinaryFormatter();
ms.Position = 0;
String strParam = item.GetIndex.ToString();
String strValue = item.GetSubIndex.ToString();
String strValue2 = item.GetPoohId.ToString();
String strValue3 = item.GetNodeId.ToString();
Group eGroup = GetGroupEnumFromID("1");
_TagCollection.Add(new TagData { TagName = strParam, Value = strValue, Value2 = strValue2, Value3 = strValue3, Group = eGroup });
}
}
catch
{
}
}
GroupedCustomers = new ListCollectionView(_TagCollection);
dataGrid2.Items.Refresh();
}
}
}
My list, GroupedCustomers, is populated with the right amount of data, but my dataGrid doesn't display the data.
Any thoughts would be much appreciated.
Regards
Tony
modified 9-Nov-12 3:08am.
|
|
|
|
|
Resolved now, amazing what a few months away can do to your memory.
Just using a simple delegate was all that was needed to post my list back to the original thread.
|
|
|
|