Freeze Columns ListView/GridView WPF - c#

I have a ListView which looks like this:
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<ListView>
<ListView.View>
<GridView>
<GridView.Columns>
...
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
There are +-30 columns, so it's a very wide screen. When the user scrolls to the right, I still want him to know which column he's on. The first four columns contain that information (ID, name, ...), so I want to freeze these columns.
Also, I'm using GridViewSort so using two ListViews will cause the sort to not work anymore.
How can I achieve this?

Related

How to make a custom UserList control in C#?

I'm making a chat program and I need a UserList control that supports icons, names, banners, status icons.
Here is a picture of the UserList I wish to clone:
As you can see the user name appears on top of the background image.
The status at the far shows red for admins, yellow for members and so on.
There are 2 more status icons that appear BEFORE the admin/member status and they show if a user is accepting private chats/messages here is a picture of that:
As you can see the UserList can contain normal (non banner like) icons as well as chat/pm status.
The UserList must scroll like any normal listview type control.
So can somebody tell me how to produce this control in C# winforms or wpf?
Any help would be greatly appreciated!
If you are using WPF, start with a ListView and set the view to a GridView.
Then set up the columns and cell templates.
Bind to properties.
<ListView Margin="10" Name="lvUsers" ItemsSource="{Binding Users}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Image Source="{Binding UserIcon}"/>
<TextBlock Text="{Binding Name}" Margin="20,0,0,0" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Status">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource PrivateChatImage}" Visibility="{Binding IsPrivateChat, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<Image Source="{StaticResource PrivateMessImage}" Visibility="{Binding IsPrivateMess, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<Image Source="{Binding StatusIcon}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Well thanks for trying to help out you lot.
I did however manage to solve the problem by custom drawing everything.
Here is the end result
http://q67.imgup.net/Untitledeb8d.png
Bascially what I did was make a WinForms UserControl then added a userList class so it hooked into OnPaint() then looped through and drew the users.
It worked fairly well so then I made a header for it with Name and Status then I made the seperator grabbable to move it around (since its drawn on it has to be all manual stuff). It properly sets the cursor to the splitter.
After that was finished I needed a way to know what user a person clicked on but that was just a simple rect search.
After that was complete I needed a scroll that worked so I moved the user paintings into a new class that inherits SplitterControl I believe and then I made it set it's scroll size based on how many users in the list * how big the elements are etc.
All in all this userlist seems to work just as good as the one I was trying to clone.
So all is well!.

Universal Windows Excel-like grid with headers

What controls are used to create an Excel-like grid with columns with headers and the columns can be resized?
In regular WPF, it was this:
<ListView>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name1}" Header="Name1"
Width="Auto" />
</GridView>
</ListView.View>
</ListView>
This displays Excel-like grid with one column with header and the whole column can be resized. But in Universal Windows Apps/WinRT, there is no GridViewColumn. How do I go about duplicating this code in Universal Windows Apps?

A table which has binding ability and also manual editing

What I want is to have a table having a first column with every row named by me one by one, not binding to some property. But all of the second column should be binded to a property. I cannot do these two with gridview since it only makes binding and does not let me to write something manually. On the other hand, I havent seen any flowdocument table tutorial in which someone mention binding. So what is the proper object suitable to fulfill mentioned two things?
ListView and GridView should meet your requirements. You have the ability to set bindings on the GridViewColumns by using DisplayMemberPath or in the CellTemplate. You can also choose not to use bindings in a column.
Take this for example:
<ListView ItemsSource="{Binding NameValuePairs}">
<ListView.Resources>
<DataTemplate x:Key="FirstCellTemplate">
<Grid Width="100">
<TextBox Width="75"/>
</Grid>
</DataTemplate>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource FirstCellTemplate}"/>
<GridViewColumn DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn DisplayMemberBinding="{Binding Value}"/>
</GridView>
</ListView.View>
</ListView>
NameValuePairs is an ObservableCollection<NameValuePair> and NameValuePair is a view model with a Name and Value properties. The first column is contains a TextBox on each row, the second is a TextBlock with the Name, and the third is a TextBlock with the Value.

Control suggestions that function like a multi column listBox

I've looked at a bunch of different controls(ListView, GridView, etc.) and can't decide which makes the most sense for me to use.
I want something that looks and functions just like a listBox with the ability to select a row with a single click, except it would contain data with multiple columns.
I'm just looking for suggestions on which control to use and how I would go about having it select a row(whether it's a selectionMode or an onClick function or what). Since I'm new to these controls I'd like some direction on which tag to place those selection options, I think I can figure out the rest however.
Thanks :)
I like using the ListView that contains a GridView as it's view. Here's how I defined it in XAML:
<ListView Name="lstCurrentInvoices" Grid.Row="4" Margin="0,0,0,0" SelectionMode="Extended" ToolTip="Invoices included in invoice file." IsTabStop="True" TabIndex="8">
<ListView.View>
<GridView>
<GridViewColumn Width="40" Header="ID" DisplayMemberBinding="{Binding ClientId}"/>
<GridViewColumn Width="170" Header="Name" DisplayMemberBinding="{Binding ClientName}"/>
<GridViewColumn Width="80" Header="Date" DisplayMemberBinding="{Binding InvoiceDate}"/>
<GridViewColumn Width="40" Header="Frequency" DisplayMemberBinding="{Binding Frequency}" />
</GridView>
</ListView.View>
</ListView>
This way you kind of get the best of both worlds. In this example, you can have multiple rows selected. You can detect which rows have been selected and grab the objects from you data source. It's really quite powerful. Hope this helps

WPF - ItemsSource equivalent for Table in FlowDocument?

I'm trying to create a Table inside a FlowDocument inside a FlowDocumentPageViewer, as seen in this tutorial. I've never created a table in WPF before, and I was expecting there to be an ItemsSourceproperty to which I could bind, like with a ListBox. I want to customize the template for each row, and I want each row's source to be an item in a collection that I pass to the entire table. So I'll have a List<MyClass> instance that would be passed to the table, and each row would show a single MyClass. How can I do that? Do I not want to use a Table within a FlowDocument? The reason I wanted to use some kind of tabular format is so that I can have a single row of column names that applies to all the rows.
I think what I wanted was to use ListView, thanks to this tutorial:
<ListView Grid.Row="0" ItemsSource="{Binding Path=MyList}" MinWidth="400"
MinHeight="200">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn
DisplayMemberBinding="{Binding Path=MyFirstField}"
Header="First Field"/>
<GridViewColumn
DisplayMemberBinding="{Binding Path=MySecondField}"
Header="Second Field"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>

Categories