How to define a DataGrid using ListView in WPF?
来源:百度文库 编辑:神马文学网 时间:2024/06/30 22:10:36
Ifyou want to have a very nice looking DataGrid you have to use ListViewcontrol. It enables you to use ControlTemplate for both the header andthe column and also has built in functionality for scrolling throughthe list. So here is how you can build a DataGrid using ListView.
First you need to define the ListView:
Asyou may have noticed I added one event handler for MouseDoubleClickevent, That is how you can enable selection feature in the list by justsetting the MouseDoubleClick or any other event on the ListView.
And this is what the select event handler looks like:
void Selected(object sender, RoutedEventArgs e)
{
ListView cmd = (ListView)sender;
string selectedItem = (string)(((System.Data.DataRowView)(cmd.SelectedItem)).Row[0]);
}
Itjust seems easier to define Style as resource for me, so here is thestyle for the ListView. I need to note that if your list is too big youwill need to enable the Scroll feature enable. This is how you shoulddo this: just set ScrollViewer.HorizontalScrollBarVisibility toVisible. The ScrollViewer embedded in the ListView will use thisproperty accordingly.
Nowyou have a very nice DataGrid. If you are interested to make yourdatagrid’s look more interesting, you can use ControlTemplate like whatI am using here:
TextBlock.TextAlignment="Center" Width="{TemplateBinding Width}"
BorderBrush="Chocolate" Background="AntiqueWhite" >
And of course you can apply this template through the style of the Header or column.
First you need to define the ListView:
Asyou may have noticed I added one event handler for MouseDoubleClickevent, That is how you can enable selection feature in the list by justsetting the MouseDoubleClick or any other event on the ListView.
And this is what the select event handler looks like:
void Selected(object sender, RoutedEventArgs e)
{
ListView cmd = (ListView)sender;
string selectedItem = (string)(((System.Data.DataRowView)(cmd.SelectedItem)).Row[0]);
}
Itjust seems easier to define Style as resource for me, so here is thestyle for the ListView. I need to note that if your list is too big youwill need to enable the Scroll feature enable. This is how you shoulddo this: just set ScrollViewer.HorizontalScrollBarVisibility toVisible. The ScrollViewer embedded in the ListView will use thisproperty accordingly.
Nowyou have a very nice DataGrid. If you are interested to make yourdatagrid’s look more interesting, you can use ControlTemplate like whatI am using here:
BorderBrush="Chocolate" Background="AntiqueWhite" >
And of course you can apply this template through the style of the Header or column.
How to define a DataGrid using ListView in WPF?
How to add a column in a Listview dynamically using WPF
How to write a Scrollable Data Grid in WPF?
Removing (all) items in a databound ListView WPF control
How to use PageFunction to create dialog behavior in WPF?
How to Think Strategically in a Recession
how to setup a basic struts project using eclipse ide
Document a package using Javadoc - Real's Java How-to
How To Write A Novel Using The Snowflake Method
WPF Data Binding Using LINQ to...
How to debug a Private Module Assembly in DotNetNuke?
how to kill a thread in python? - Python
How to debug a Private Module Assembly in DotNetNuke
How to Think About Pricing Strategies in a Do...
How to Add Properties to Custom WPF Control
How to determine the size of a raw device (in a C programm)
GridView、DataGrid、DataList、Repeater、ListView、...
How to power leveling a char in Diablo II from 1-85level?
How to find a file?
How To Compile A Kernel
How to Start a Startup
how to read a paper
How to read a book!!!
how to make a sop