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>
Related
I'm prrety new to wpf, and i try to make a GridView that inside ListView to response to double click on row in the view
I try to make this-
<ListView
ItemsSource="{Binding Products}">
<ListView.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding Test}" />
</ListView.InputBindings>
<ListView.View>
<GridView>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn
Header="ID"
DisplayMemberBinding="{Binding ID}" />
<GridViewColumn
Header="Name"
DisplayMemberBinding="{Binding Name}" />
<GridViewColumn
Header="Category"
DisplayMemberBinding="{Binding Category}" />
<GridViewColumn
Header="Price"
DisplayMemberBinding="{Binding Price}" />
</GridView>
</ListView.View>
<ListView />
when Test is an ICommand property in the view model.
But it's not responding to double click.
What am I getting wrong, and mabye there is another way?
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>
Im a bit new to WPF and I cant seem to figure out why the items I add to a listview are displaying empty.
Here is my XAML
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=Description}" />
</GridView>
</ListView.View>
Here is the code
lstBillGroups.Items.Add(New StlReportPlugins.BillingIncrements With {.ID = 100, .Description = "Test"})
Here is the output
(couldnt post a pic because i dont have enough points)
Link to pic
Any Ideas?
This is how your XAML should look like
<ListView ItemsSource={Binding Source={StaticResource BillingIncrements}}>
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
If you have a look at output window in VS while debugging your app you'll see a bunch of WPF binding errors, which helps a lot to spot mistakes.
I want to display a simple schema of a database in a treeview with 1 level of depth.
So I have a collection of tables, whose name I'd like to display as a header of the elements, and for each table a collection of columns with name, type, etc..
However in each table I want to display those columns definition in a grid, with a header specifying the properties of the columns definition, and in each row, the definition itself.
One way to make this work is to see that as a treeview where each table has a sequence of one child (the entire collection of column definition), then displayed as a grid :
<TreeView ItemsSource="{Binding Tables}" x:Name="treeView" MinWidth="400" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=ListofONEelement}">
<TextBlock Text="{Binding Path=TableName}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding GroupOfColumnDefinition}">
<ListView.View>
<GridView>
<GridViewColumn Header="ColumnName" DisplayMemberBinding="{Binding Path=Item1}" />
<GridViewColumn Header="Model" DisplayMemberBinding="{Binding Path=Item2.Model}" />
<GridViewColumn Header="ColumnStatus" DisplayMemberBinding="{Binding Path=Item2.ColumnStatus}" />
<GridViewColumn Header="ColumnType" DisplayMemberBinding="{Binding Path=Item2.ColumnType}" />
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
But I had to create this intermediate structure ListofONEelement to make this works, as hierarchy in the treeview exists only if there are items to enumerate.
Are there other, nicer ways to do this, directly in XAML, that would not require to have a custom type created in my ViewModel ?
Actually put the one item in the TreeView. Don't use HierarchicalDataTemplate.
<TreeView ItemsSource="{Binding Tables}">
<TreeView.ItemTemplate>
<DataTemplate>
<TreeViewItem Header="{Binding TableName}">
<ListView ItemsSource="{Binding GroupOfColumnDefinition}">
<ListView.View>
<GridView>
<GridViewColumn Header="ColumnName" DisplayMemberBinding="{Binding Path=Item1}" />
<GridViewColumn Header="Model" DisplayMemberBinding="{Binding Path=Item2.Model}" />
<GridViewColumn Header="ColumnStatus" DisplayMemberBinding="{Binding Path=Item2.ColumnStatus}" />
<GridViewColumn Header="ColumnType" DisplayMemberBinding="{Binding Path=Item2.ColumnType}" />
</GridView>
</ListView.View>
</ListView>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
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)