Do not use on any
shared computer
May 16, 2008 11:32pm pdt
12.05.2007 at 03:32AM PST, ID: 23002637
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How do I do databinding in WPF - ListBox and ListView
Tags: wpf, listview, listbox
Hi,

I am using VS 2008 Beta 2 on Vista.  I am finding databinding on WPF a little difficult.  I have seen lots of examples of people binding to textboxes.  Basically I have a table users with a few columns - firstName, lastName, email.  I have a stored procedure that returns a list of users.  I have created a SqlDataAdapter that gets data and fills a DataTable dt.  I have a a listview lvUsers.  Now how do I bind the data in dt to lvUsers?  Used to be easy as control.DataSource = dt

Thanks
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: gbzhhu
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: A
Views: 422
Translate:
Loading Advertisement...
12.05.2007 at 07:46AM PST, ID: 20412161

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 08:19AM PST, ID: 20412549

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 08:48AM PST, ID: 20412848

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 08:59AM PST, ID: 20412972

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:11AM PST, ID: 20413103

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:17AM PST, ID: 20413160

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:23AM PST, ID: 20413205

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:37AM PST, ID: 20413305

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:42AM PST, ID: 20413355

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 09:51AM PST, ID: 20413432

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.05.2007 at 10:04AM PST, ID: 20413523

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.06.2007 at 01:24AM PST, ID: 20418282

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.10.2008 at 10:53AM PST, ID: 20629845

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
12.05.2007 at 07:46AM PST, ID: 20412161

Rank: Wizard

I, too, find that WPF is a strange new world, that takes a lot to learn.

Have you seen articles like this?

WPF Data Binding Tutorial
http://coredotnet.blogspot.com/2006/05/wpf-data-binding-tutorial.html

Bob
 
12.05.2007 at 08:19AM PST, ID: 20412549
Hi Bob,

I thought only you would be the one attempting to answer this :-)

I have seen that article and numerous others like these.

http://blogs.msdn.com/henryh/archive/2005/06/23/431846.aspx
http://msdn.microsoft.com/msdnmag/issues/07/12/DataPoints/

I have now managed to databind the ListBox.  It is displaying fields vertically, i.e

Row1
  field 1
  field 2
  field 3
Row 2
  field 1
  field 2
  field 3

And I have no styling.  Having used to doing the styling via property pages and also creating templates via GUI, I am now wondering why we have to code GUI in XAML which is simple looking language but certainly not easy.

What I was attempting to do was load a list of users from DB and show them in List control (ListBox, ListView etc) then user types a few characters on textbox I use for filtering then I would run some LINQ to get users whose names start with the characters entered.  all works apart from styling (and when LINQ is applied to filter users I get the right number of users back but the ListBox although it contains the correct number of users does not display them - there must some tweaking I am missing).  All in all it is weird way of doing things

I am just looking at the web for a WPF book.  It is said that every Windows Forms developer must learn WPF so better start now!

Hassan
 
12.05.2007 at 08:48AM PST, ID: 20412848

Rank: Wizard

XAML is a completely different beast than anything that I have seen in a long time.  Have you seen or used anything like Expression?  

What kind of styling are you looking for?

Bob
 
12.05.2007 at 08:59AM PST, ID: 20412972
Yeah I agree about XAML!  I guess it is a matter of getting used to it.  I prefer object based priogramming as opposed to declarative.

Do you mean Expression Blend?  I haven't used it.  Does it come with VS 2008 (I am using VS 2008 Beta 2)?

Styling wise I am after 2 types of styling, basic which I should be able to achieve at some point and fancy which may not be possible

Basic
 - display header row with column header text
 - display fields as columns horizontally like a datagrid would

Fancy (as above plus)
 - header bgcolour - gradient
 - borders and gradient colour on selected rows

That'd do for now :-)
 
12.05.2007 at 09:11AM PST, ID: 20413103

Rank: Wizard

Yeah, Expression Blend ;)

It is a separate application from VS 2008, but comes in the MSDN subscription.  It makes it easier to style XAML.

How is your ListBox declared?

Bob
 
12.05.2007 at 09:17AM PST, ID: 20413160
I see.  We only received Beta 2 and we are waiting for the RTM stuff.  I will install Expression Blend then and hope it helps.

My whole XAML below

<Window x:Class="WpfApp1.Users"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Users" Height="402" Width="495">
    <Grid>
        <Button Height="25" HorizontalAlignment="Left" Margin="18,0,0,24" Name="btnUsers" VerticalAlignment="Bottom" Width="109" Click="btnUsers_Click">Get Users</Button>
        <TextBox Height="25" Margin="140,0,94,25" Name="txtUser" VerticalAlignment="Bottom" />
        <ListBox Margin="10,10,12,66" Name="listBox1" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=firstName}" />
                        <TextBlock Text="{Binding Path=lastName}"/>
                        <TextBlock Text="{Binding Path=email}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <TextBlock Height="20" HorizontalAlignment="Left" Margin="26,0,0,3" Name="textBlock1" VerticalAlignment="Bottom" Width="104" />
        <TextBox Height="20" Margin="140,0,188,2" Name="textBox1" VerticalAlignment="Bottom" />
    </Grid>

</Window>


And my whole code behind minus using directives

    public partial class Users : Window
    {
        DataTable dt = new DataTable();

        public Users()
        {
            InitializeComponent();
           
            this.Loaded += new RoutedEventHandler(Users_Loaded);
        }

        void Users_Loaded(object sender, RoutedEventArgs e)
        {
            SqlDataAdapter adaptor = new SqlDataAdapter("cms_getUsers", "server=dbserver;database=bayer_bioscience;user id=webBayer;password=password;");
            adaptor.Fill(dt);
            DataContext = dt;

            //this.listView1.DataContext = ds.Tables[0];
            //Binding bind = new Binding();
            //bind.Source = ds.Tables[0];
            //this.listView1.SetBinding(ListView.ItemsSourceProperty, bind);
           
        }

        private void btnUsers_Click(object sender, RoutedEventArgs e)
        {
            var query = from r in dt.AsEnumerable()
                        where r.Field<string>("lastName").StartsWith(this.txtUser.Text)
                        select r;

            //DataContext = query;
            //listBox1.DataContext = DataContext;
        }
    }

 
12.05.2007 at 09:23AM PST, ID: 20413205
Bob,

Are you any good at Mobile dev? Windows Mobile 5 and CF 2.0?

I have this issue that I couldn't fix for 5 months now !!!!
 
12.05.2007 at 09:37AM PST, ID: 20413305

Rank: Wizard

Here is a LinearGradientBrush for the Background:

        <ListBox Margin="10,10,12,66" Name="listBox1" ItemsSource="{Binding}">
            <ListBox.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,5">
                    <GradientStop Color="Blue" Offset="0.0" />
                    <GradientStop Color="Red" Offset="0.25" />
                    <GradientStop Color="White" Offset="0.75" />
                </LinearGradientBrush>
            </ListBox.Background>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=firstName}" />
                        <TextBlock Text="{Binding Path=lastName}"/>
                        <TextBlock Text="{Binding Path=email}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

The two properties for the gradient orientation are StartPoint and EndPoint.  For vertical, set StartPoint.X = EndPoint.X, and EndPoint.Y > StartPoint.Y, and for horizontal, reverse that.  For diagonal, you could use 0,0 and 1,1.

Bob
Accepted Solution
 
12.05.2007 at 09:42AM PST, ID: 20413355

Rank: Wizard

>>I have this issue that I couldn't fix for 5 months now !!!!
Is there a question open?

Bob
 
12.05.2007 at 09:51AM PST, ID: 20413432
I had a question open but it is now closed - I'll explain.

Basically this issue doesn't stop program from running.  Just that when an exception occurs I get a generic error explained here
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2460541&SiteID=1

I can open a question if you could look into it or find others whop are good at this topic.  I only know of one Mikal613 but he/she could not fix this one.

by the way, tyhe gradient colour you showed me is brilliant! thanks
 
12.05.2007 at 10:04AM PST, ID: 20413523

Rank: Wizard

You would have to open another question, and give me the URL for it before I could help you.

Bob
 
01.10.2008 at 10:53AM PST, ID: 20629845
Sorry Bob.  left this open too long.  I have abandoned my WPF  research for now.  I bought a book and want to read it first then get back to it.  Thanks for helping as always

H
 
 
20080206-EE-VQP-25 / EE_QW_2_20070628