Results 1 to 4 of 4

Thread: BindingSource filter help

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    London United Kingdom
    Posts
    334

    Post BindingSource filter help

    Hi Guys, could you look at the code below on how I fetch information and help me on how I can display the Actors name on a Label.

    Code:
    Private Sub LoadMovieDetails()
            Try
    
                Dim cmd As SqlCeCommand
                cmd = New SqlCeCommand("SELECT MovieDetails.MovieID,MovieDetails.ActorID,Movies.MovieID, Movies.FilmName,Movies.CatID,Actors.ActorID, Actors.ActorName,  Movies.Poster, " _
                                       & "Categories.CatName, Categories.CatID, Convert(nvarchar, Movies.FilmDate, 107) as FilmDate FROM MovieDetails " _
                                       & " INNER JOIN Actors ON MovieDetails.ActorID = Actors.ActorID INNER JOIN Movies ON MovieDetails.MovieID = Movies.MovieID " _
                                        & "INNER JOIN Categories on Movies.CatID = Categories.CatID", sCon)
    
                da = New SqlCeDataAdapter(cmd)
                cbd = New SqlCeCommandBuilder(da)
                dsPictures.Clear()
                da.Fill(dsPictures, "Movies")
                dtView.DataSource = dsPictures.Tables(0)
            Catch sqlExc As SqlCeException
                MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
                    MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End Try
            sCon.Close()
        End Sub
    This is how I do it. First either the movie name or actors name can be filter and display in a ListBox. So let us say the Actors name starting 'S' has been filter into the ListBox, when you select a name all the movies that actor is in should be filtered and the details are displayed where you can navigate back and forward. I am able to do all this but how to display all the actors name in the movie on a Label.

    Secondly, when I filter by movie names the ListBox display same movie more than twice depending how many actors. This is how I filter it and I do similar for the actors

    Code:
    Private Sub ShowFilmNames()
            Dim MyRow As DataRowView, CurrentMovie As String, LastMovie As String
            If Me.txtMovies.Text <> "" Then
                If Me.chkTitle.Checked Then
                    Me.LoadMovieDetails()
    
                    dtView.Filter = String.Format("FilmName LIKE '{0}&#37;'", Me.txtMovies.Text)
                    
                    Me.BindingContext(dtView).Position = 0
                    LastName = ""
                    For Each MyRow In dtView
                        CurrentMovie = Trim(CStr(MyRow(("FilmName"))))
                        If CurrentMovie <> LastMovie Then
                            Me.lstMovieList.Items.Add(CurrentMovie)
                            LastMovie = CurrentMovie
                        End If
                    Next
            End If
            End If
        End Sub
    Also I have this in the ListBox SelectedIndexChange

    Code:
     Private Sub lstMovieList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstMovieList.SelectedIndexChanged
    
            If Me.chkTitle.Checked Then
                dtView.Filter = "FilmName = '" + CStr(lstMovieList.SelectedItem) + "'"
            ElseIf Me.chkCategory.Checked Then
                dtView.Filter = "CatName = '" + CStr(lstMovieList.SelectedItem) + "'"
            ElseIf Me.chkActor.Checked Then
                dtView.Filter = "ActorName = '" + CStr(lstMovieList.SelectedItem) + "'"
            End If
    
    
            Dim row = DirectCast(dtView.Current, DataRowView)
      
            If row IsNot Nothing Then 'Allow for no item selected.
    
                Dim data = TryCast(row("Poster"), Byte())
                Dim ms As MemoryStream
                If data IsNot Nothing Then 'Allow for DBNull.Value.
                    ms = New MemoryStream(data)
                    Me.picImage.Image = Image.FromStream(ms)
                    Me.picImage.Image = New Bitmap(ms)
                    ms.Close()
                End If
                Me.lblTitle.Text = row("FilmName")
                Me.lblActors.Text = row("ActorName")
                Me.lblCategory.Text = row("CatName")
                Me.lblDate.Text = Format(row("FilmDate"), "dd MMMM yyyy")
            End If
    
            Me.BindingContext(dtView).Position = 0
            Me.btnFirst.Enabled = Me.BindingContext(dtView).Count > 1
            Me.btnNext.Enabled = Me.BindingContext(dtView).Count > 1
            Me.btnPrevious.Enabled = Me.BindingContext(dtView).Count > 1
            Me.btnLast.Enabled = Me.BindingContext(dtView).Count > 1
            
        End Sub
    Thanks for your kind help.
    Last edited by wiadus; Jun 12th, 2011 at 08:59 AM.

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