ComponentOne FlexGrid is empty - wpf

I just started using ComponentOne. Among other things, I need DataGrid with filtering capability for my WPF Caliburn.Micro application. So I tried to replace my common DataGrid with C1DataGrid, then C1FlexGrid, but in both cases the DataGrid was empty.
Here is my code:
<c1:C1FlexGrid x:Name="EnrollmentFiles" Grid.Row="1"
AutoGenerateColumns="False"
BaseControls:DataGridExtension.Columns="{Binding EnrollmentFileColumns}"
IsReadOnly="True"
SelectedItem="{Binding Path=SelectedEnrollmentFile, Mode=TwoWay}">
</c1:C1FlexGrid>
Could you please tell me what I am missing? Also, should I use C1DataGrid or FlexGrid?
Thanks

It's possible that by having SelectedItem bound the convention isn't working. If you're using the convention and want ItemsSource bound to EnrollmentFiles and you want to use SelectedItem, then create a property called SelectedEnrollmentFile and CM will do the SelectedItem binding too.

Related

Visifire/WPF databinding issues (Visifire v3.6.8)

I have a very basic databinding issue with the Visifire WPF charting tool in the last open-source version, v3.6.8, before it became commercial. I want to bind an ObservableCollection<> to the DataSource-Property of a DataSeries. It just doesn't work when I bind the property in XAML. When I bind the data in the code behind, it works fine.
I am using the collection for a DataGrid as well and there everything works fine.
The output log doesn't show any binding issues.
The get/set accessors of the DataSource property of the DataSeries object are never accessed when binding the property in XAML, I just don't get why. The dependency property is registered at creation of the DataSeries object.
Are there any known issues with this or am I missing something basic?
The XAML:
<DataGrid x:Name="grid" Grid.Column="0" ItemsSource="{Binding TransverseParallelShearLCS}"></DataGrid>
<Charts:Chart Grid.Column="1" x:Name="chart" ZoomingEnabled="True" AnimatedUpdate="True" ScrollingEnabled="False">
<Charts:Chart.Series>
<Charts:DataSeries RenderAs="Line" DataSource="{Binding TransverseParallelShearLCS}" AutoFitToPlotArea="True">
<Charts:DataSeries.DataMappings>
<Charts:DataMapping MemberName="XValue" Path="X"></Charts:DataMapping>
<Charts:DataMapping MemberName="YValue" Path="Y"></Charts:DataMapping>
</Charts:DataSeries.DataMappings>
</Charts:DataSeries>
</Charts:Chart.Series>
</Charts:Chart>
Please try the below sample example from Visifire Example Area and check.
http://visifire.com/silverlight_examples_details.php?id=10

Combobox's SelectedValue (or SelectedItem) OneWay binding not working. Any ideas?

In the below window, the Existing Reports combo is bound to an observeablecollection of reportObjects. I have a reportObject property currentReport bound to the combo's SelectedValue property, OneWay. However, that's not working when bound in XAML.
SelectedValue="{Binding currentReport, Mode=OneWay}"
TwoWay binds fine, but I can't do it that way without writing an undo() method to the reportObject class. I'm binding the currentReport's properties to the various textboxes for editing. I want to bind OneWay so the source doesn't get changed. The currentReport's properties are all TwoWay bound to the corresponding textboxes so when I update the table in SQL [Save], it'll pull from that object, who's data is current.
<TextBox Text="{Binding currentReport.reportName, Mode=TwoWay}"
All of the properties bound from currentReport to the textboxes work fine as well. The only problem is the OneWay binding from the SelectedValue to the currentReport object. Does anyone have any ideas how to get this to work? I saw there was a bug, but the post I saw was 2009.
Sorry about the yellow. Not my idea. =)
EDIT: Added this XAML just in case.
<ComboBox ItemsSource="{Binding reportsCollection}" SelectionChanged="cboReports_SelectionChanged"
DisplayMemberPath="displayName"
SelectedValue="{Binding currentReport, Mode=TwoWay}"
x:Name="cboReports" Width="342" Height="40" VerticalAlignment="Center"/>
Forget about you need to change values - that is a separate problem - need to review your data design. Start with the UI problem question. If you want a user to be able to select an item from a combo box then it must have two way binding. Your first question is SelectedValue="{Binding currentReport, Mode=OneWay}" is failing why?

How to set a filter for a DataGrid ItemSource via MVVM

I have a DataGrid bound to a CollectionViewSource in XAML.
<Window.Resources>
<local:MainWindowViewModel x:Key="ViewModel"/>
<CollectionViewSource x:Key="cvsEntries"
Source="{Binding LogEntriesStore,
Source={StaticResource ViewModel}}"/>
</Window.Resources>
LogEntriesStore is an ObservableCollection (LogEntry is a DTO that's not important in this discussion)
The DataGrid is declared as:
<DataGrid AutoGenerateColumns="False"
Margin="0"
Name="dataGrid1"
ItemsSource="{Binding Source={StaticResource cvsEntries}}"
IsReadOnly="True">
Now I have context menus on various cells in this DataGrid, to kick off a request for filtering. Right click on a cell, and pick filter to filter all the rows, and show only this particular value.
The MVVM gets the request to filter, but the now the tricky bit. How do I set the filter on the CollectionViewSource?
(as an aside -- this would have been a walk in the park with a Silverlight PagedCollectionView but that doesn't seem to be available in WPF, is that right?)
Very simple. You just need to move the collection view inside the view model:
In MainWindowViewModel define a property of type ICollectionView:
public ICollectionView LogEntriesStoreView { get; private set; }
Right after you have initialized the LogEntriesStore property, you need to initialize the LogEntriesStoreView property with the following code:
LogEntriesStoreView = CollectionViewSource.GetDefaultView(LogEntriesStore);
Then you need to remove the CollectionViewSource from XAML and modify the ItemsSource binding to point to the newly created collection view property:
<DataGrid AutoGenerateColumns="False"
Margin="0"
Name="dataGrid1"
ItemsSource="{Binding LogEntriesStoreView, Source={StaticResource ViewModel}}"
IsReadOnly="True">
That's it. Now you have the access to the collection view inside your view model, where you can modify the filter.
There are several solutions to your problem, but in my opinion, the best solutions are the ones which uses only styles with the standard WPF DataGrid control without inventing a new inherited DataGird type or depending on another third-party control. The followings are the best solutions I found:
Option 1: which I personally use: Automatic WPF Toolkit DataGrid Filtering
Option 2: Auto-filter for Microsoft WPF DataGrid

DataGridComboBoxColumn ItemSource Binding Doesn't work

In all of the examples of DataGridComboBoxColumn ItemSource comming from the Resources.
Couldn't it be binding directly to a list in the CodeBehind ?
It depends what you mean with binding directly to a list in the CodeBehind.
You can declare the column with...
<DataGridComboBoxColumn x:Name="m_column" ../>
and then in code-behind set the ItemsSource...
m_column.ItemsSource=yourItemsSource
However you can not directly use the binding in XAML, something like:
<DataGridComboBoxColumn ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=YourElement}}"/>
because DataGridComboBoxColumn is not a part of the visual tree.
There are workarounds for this. The most simple is using a DataGridTemplateColumn and placing the ComboBoxes directly in the edit-DataTemplate. If you use a ViewModel, you can provide the data through it. Otherwise look here and here for workarounds.

wpf combobox binding issue

when i bind one combobox with other combobox items... with the following code
<ComboBox ItemsSource="{Binding ElementName=cbo1, Path=Items}" Name="cbo2" />
it works fine but when i select something from cbo1 and come back to select something in cbo2.. it doesn't list anything nor cbo1 does...
what could be wrong?
The Items property is a CollectionView which wraps the ItemsSource, and includes things like the currently selected item, sort order, etc. If you set ItemsSource on an ItemsControl, your data is automatically wrapped in a CollectionView, and that's what gets set as the Items property. I suspect that this class isn't suitable for sharing between two controls.
If you're using ItemsSource to set the data on cbo1, you could maybe bind to ItemsSource instead? That is:
<ComboBox ItemsSource="{Binding ElementName=cbo1, Path=ItemsSource}" Name="cbo2" />
Haven't had chance to test this, but it's an educated guess :-)

Resources