This works perfectly, except that I need some kind of template to display the Selected Item of the ComboBox? Currently the bindings work as expected, but the ComboBox displays: "Systems.Windows.Controls.ListView Items.Count:20".
I would like it to display a horizontal StackPanel or Grid containing the GridViewColumn items (ID, Closed Date, Customer, Job Name).
<ComboBox Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Left"
IsTextSearchEnabled="False" Width="700"
IsEditable="True">
<ListView ItemsSource="{Binding ActiveJobObservCollection}"
SelectedItem="{Binding SelectedActiveJob, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Job ID" DisplayMemberBinding="{Binding JobID}"/>
<GridViewColumn Width="100" Header="Closed Date" DisplayMemberBinding="{Binding ClosedDate, StringFormat=d}"/>
<GridViewColumn Width="200" Header="Customer Name" DisplayMemberBinding="{Binding CustomerName}"/>
<GridViewColumn Width="300" Header="Job Name" DisplayMemberBinding="{Binding JobName}"/>
</GridView>
</ListView.View>
</ListView>
</ComboBox>
If I have understood your issue correctly, that you want to display this 4 columns (ID, Closed Date, Customer, Job Name) in horizontal manner where data is coming from this ActiveJobObservCollection collection
if that is the case then bind itemsource and selecteditem property directly to gridview instead of listview.
Related
I used list view with a single column, I would like this column with the same size list view with.
I mean Just one column fill the all with of the list view.
I tried this but didn't work...
<ListView Grid.Row="1" Grid.Column="1" x:Name="LvErrorList">
<ListView.View>
<GridView>
<GridViewColumn Width="{Binding ActualWidth, ElementName=LvErrorList}" Header="Status" DisplayMemberBinding="{Binding ErrorMessage}" />
</GridView>
</ListView.View>
</ListView>
I tried
<GridViewColumn Width="Auto" Header="Status" DisplayMemberBinding="{Binding ErrorMessage}" />
But some text are longer than the with of the ListView.
Becaues i don't know the user screen size i can't set max-width property.
Does anyone know how to fix this please?
You can try this way instead.
<ListView Grid.Row="1" Grid.Column="1" x:Name="LvErrorList">
<ListView.View>
<GridView>
<GridViewColumn Header="Status" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ErrorMessage}" Width="{Binding ElementName=LvErrorList,Path=ActualWidth}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
How to put a Combobox to a special row of a listview (WPF, VB.net)?
There is a ListView that has two columns. The columns are "Parameter" and "Values". The second column has different types (such as numbers, strings and "Selectable values") and is editable. The "Selectable values" have to appear in a Combobox.
One of the ways that I think about, is conditional XAML tags (I don`t know if it is possible or not ?) .
I tried this code but it shows Combobox for all rows in listview :
<ListView x:Name="listView"
HorizontalAlignment="Left"
Height="237"
Margin="40,34,0,0"
VerticalAlignment="Top"
Width="447"
ItemsSource="{Binding Values}">
<ListView.View>
<GridView>
<GridViewColumn Header="Parameter"
DisplayMemberBinding="{Binding Path=LName}"
Width="100" />
<GridViewColumn Header="Value"
Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ListView}, Path=ItemsSource}"
Width="120">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Type}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I only want to use Combobox for one row while the type of the rest of rows are double or string. How can I do this?
Iam having a ListView named "ListLoginDetails" in WPF. In which I displays two columns namely "User_Name", "Password" through DataSet. Now I haven to Sort the ListView on Both Ascending & Descending Order. Based upon the button clicked.....
Home.Xaml:
<ListView Name="ListLoginDetails" ItemsSource="{Binding Path=Table}" Margin="18,0,0,0" Grid.RowSpan="3" >
<ListView.View>
<GridView x:Name="gridView">
<GridViewColumn Width="100" Header="User_Name" DisplayMemberBinding="{Binding Path=Id}" />
<GridViewColumn Width="140" Header="Password" DisplayMemberBinding="{Binding Path=Password}" />
</GridView>
</ListView.View>
</ListView>
I am having trouble adding a row that displays all the values of the member of an object.
Here is how I have set up my listview:
<ListView Height="178" HorizontalAlignment="Left" Margin="238,31,0,0" Name="SpoolSheetListView" VerticalAlignment="Top" Width="555" HorizontalContentAlignment="Stretch" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="85" Header="Column 1" />
<GridViewColumn Width="120" Header="Column 2" />
<GridViewColumn Width="120" Header="Column 3" />
<GridViewColumn Width="120" Header="Column 4" />
<GridViewColumn Width="115" Header="Column 5" />
</GridView>
</ListView.View>
</ListView>
say, myObject has 5 members: member1 to member5, which are all of type string. How do I add a single row in the ListView for that object?
Thanks again people!
WPF list controls work best when you use them with data binding; you should bind the ItemsSource of the ListView to a list of objects, and bind each column to a property of these objects.
<ListView ItemsSource="{Binding Items}" Height="178" HorizontalAlignment="Left" Margin="238,31,0,0" Name="SpoolSheetListView" VerticalAlignment="Top" Width="555" HorizontalContentAlignment="Stretch" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="85" Header="Column 1" DisplayMemberBinding="{Binding Member1}" />
<GridViewColumn Width="120" Header="Column 2" DisplayMemberBinding="{Binding Member2}" />
<GridViewColumn Width="120" Header="Column 3" DisplayMemberBinding="{Binding Member3}" />
<GridViewColumn Width="120" Header="Column 4" DisplayMemberBinding="{Binding Member4}" />
<GridViewColumn Width="115" Header="Column 5" DisplayMemberBinding="{Binding Member5}" />
</GridView>
</ListView.View>
</ListView>
(Items being a property of the DataContext that returns a collection of objects)
To add a row to the ListView, you just need to add an item to the Items collection (note that the collection should implement INotifyCollectionChanged so that the ListView is notified; the ObservableCollection<T> class works fine for most cases)
I have a Listview:
<ListView ItemsSource="{Binding FieldMap.SourceTargetFieldMap, Mode=Default}">
<ListView.View>
<GridView>
<GridViewColumn Header="Source Fields" CellTemplate="{StaticResource sourceFieldsTemplate}"/>
<GridViewColumn Header="Source Values" CellTemplate="{StaticResource =sourceValueTemplate}">
<GridViewColumn Header="Target Field" CellTemplate="{StaticResource targetFieldTemplate}"/>
</GridView>
</ListView.View>
</ListView>
And I also have cell data templates that these bind to:
<DataTemplate x:Key="sourceFieldsTemplate">
<ComboBox x:Name="cbSourceField" SelectedValue="{Binding Path=SourceField, Mode=TwoWay}" DisplayMemberPath="FieldName" ItemsSource="{Binding SourceFieldValues}" Width="120" />
</DataTemplate>
<DataTemplate x:Key="sourceValueTemplate">
<TextBox x:Name="tbSourceValue" Margin="5,0,0,0" DataContext="{Binding ElementName=cbSourceField, Path=SelectedItem}" Text="{Binding Path=FieldValue, Mode=TwoWay}" TextWrapping="Wrap" Width="115" />
</DataTemplate>
<DataTemplate x:Key="targetFieldTemplate">
<TextBox x:Name="tbTargetField" Margin="5,0,0,0" Text="{Binding Path=TargetField}" TextWrapping="Wrap" Width="155" IsReadOnly="True"/>
</DataTemplate>
What I want to do is, bind the Source Value textbox field to the selected item of the SourceFields combobox. So when an item is selected from the sourcefield combobox, a property from the selectedItem (which is actually a object with two properties - something like fieldname and value) populates the textbox.
Both controls are "hidden" within datatemplates and I am not sure how to populate one from the other??
Any ideas? Much appreciated!!
Matt
You could insert a ContentConteol where content is bound to selected item of your listview - then the datetemplate should take care of displaying - I would set readonly on the textbox since altering the text will have no effect.