Results 1 to 6 of 6

Thread: Listview won't show results

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    Listview won't show results

    Hello guys, I am trying to bind a dataset to the list view. I have included a gridview inside it in order to do that. I try to setup the column headers and the displaymemberbindings at runtime. I get no errors but no data is showing. Any help would be greatly appreciated.

    Thanks in advance
    Samv12

    Code:
      Dim x As New GridViewColumnCollection
    
                            Dim int As Integer
    
                            For int = 0 To ds.Tables(0).Columns.Count - 1 Step 1
                                Dim y As New GridViewColumn
                                y.Header = ds.Tables(0).Columns(int).ColumnName
                                y.DisplayMemberBinding = New Binding(ds.Tables(0).Columns(int).ColumnName)
                                x.Add(y)
                            Next
    
                            GridView.SetColumnCollection(Gridview1, x)
                            results.View = Gridview1
    
                            results.DataContext = ds.Tables(0).DefaultView

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Listview won't show results

    Any reason why you are doing that at runtime? I find it easier to just use the DisplayMemberBinding attribute in XAML and then you dont need to do any loops like that in code.

    As for why its not working, have you had a look at the "Immediate Window" in Visual Studio when your app is running because that often tells you why a binding has failed (failed bindings are designed not to throw exceptions)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Listview won't show results

    Time out...

    Listview or GridView? They are NOT the same thing...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    Re: Listview won't show results

    Quote Originally Posted by chris128 View Post
    Any reason why you are doing that at runtime? I find it easier to just use the DisplayMemberBinding attribute in XAML and then you dont need to do any loops like that in code.

    As for why its not working, have you had a look at the "Immediate Window" in Visual Studio when your app is running because that often tells you why a binding has failed (failed bindings are designed not to throw exceptions)
    oh didn't know that man will look into it. The thing is the listview is supposed to be dynamic, so the columns will vary depending upon the situation, so hard coding it in the xaml is not an option for me. Hope am making sense.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    Re: Listview won't show results

    Quote Originally Posted by techgnome View Post
    Time out...

    Listview or GridView? They are NOT the same thing...

    -tg
    Your right man. am a newbie to xaml but this is my code:
    Code:
    <ListView Margin="6,326,76,0" Name="results" Visibility="Hidden" Height="113" VerticalAlignment="Top" HorizontalAlignment="Left" Width="232" ItemsSource="{Binding Path=Table}" >
                <ListView.Background>
                    <LinearGradientBrush>
                        <GradientStop Color="Gray" Offset="0"/>
                    </LinearGradientBrush>
                </ListView.Background>
                <ListView.View>
                    <GridView x:Name="Gridview1">    
                    </GridView>
                </ListView.View>
            </ListView>
    So its basically a gridview inside a listview in order to have columns, as i think the listview only has item properties.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Listview won't show results

    Quote Originally Posted by techgnome View Post
    Time out...

    Listview or GridView? They are NOT the same thing...

    -tg
    Not in winforms no, but a ListView in WPF can house a GridView element inside it's View property to make it look like a datagrid (just as the OP has shown in his example XAML in the post above this one)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width