Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27517

VS 2012 [RESOLVED] Trouble with filter and datagridview

$
0
0
Hello: I'm working on a windows form that has a datagridview and a filter above it.

When the page first loads, the filter is set to 'UNASSIGNED'. It's possible that at times, there could be no records so I wanted to test that senerio in which there's no records for
UNASSIGNED but there are records for the other status's in the filter.

So, when the page first loads, the filter is UNASSIGNED and there's no records (see first pic);
After, the user filters on ASSIGNED and there is records (see 2nd pic);
After, the user filters back on UNASSIGNED - and the records in the grid don't budge...they still display ASSIGNED? Why?

Here's my code when the page first loads: (not putting the entire thing....because believe this is enough to give you an idea)

Code:

Public Sub AssignJobs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim iColIndex As Integer = 0

        'CAUSES cboJobNoFilter_SelectedIndexChanged to fire(code below this)
        cboStatusFilter.SelectedIndex = 0

        With Me.DataGridView1
            .RowsDefaultCellStyle.BackColor = White
            .AlternatingRowsDefaultCellStyle.BackColor = LightYellow
        End With


        DataGridView1.AllowUserToAddRows = False
        DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter


        'ADD THE COLUMNS AND THEIR PROPERTIES:
        '*******************
        'JOB NO COLUMN:
        Dim JobId As New DataGridViewTextBoxColumn()
        JobId.Name = "JobId"
        DataGridView1.Columns.Add(JobId)
        'needs this for it to associate the database column with it:
        DataGridView1.Columns(0).DataPropertyName = "jobid"
        DataGridView1.Columns(0).HeaderText = "Job No"
        DataGridView1.Columns(0).ReadOnly = True

        'JOB NO COLUMN:
        Dim RequestRcvdDate As New DataGridViewTextBoxColumn()
        RequestRcvdDate.Name = "RequestRcvdDate"
        DataGridView1.Columns.Add(RequestRcvdDate)
        'needs this for it to associate the database column with it:
        DataGridView1.Columns(1).DataPropertyName = "RequestRcvdDate"
        DataGridView1.Columns(1).HeaderText = "Rq Rcvd"
        DataGridView1.Columns(1).Width = 100
        DataGridView1.Columns(1).ValueType = GetType(Date)
        DataGridView1.Columns(1).ReadOnly = True

        ''*******************
        ''LOG JOB COLUMN:
        Dim logJob As New DataGridViewLinkColumn()
        logJob.Name = "Log Job"
        DataGridView1.Columns.Add(logJob)
        DataGridView1.Columns(2).DataPropertyName = "logjobs"
        DataGridView1.Columns(2).HeaderText = "Log Job"

        ''*******************
        ''LOG BOM COLUMN:
        Dim logBom As New DataGridViewLinkColumn()
        logBom.Name = "Log Bom"
        DataGridView1.Columns.Add(logBom)
        DataGridView1.Columns(3).DataPropertyName = "logboms"
        DataGridView1.Columns(3).HeaderText = "Log Bom"

Code:

Private Sub cboStatusFilter_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboStatusFilter.SelectedIndexChanged
      BindDataTables()   
    End Sub

ONE MORE....HERE'S MY BINDDATATABLES FUNCTION
Code:

    Public Function BindDataTables() As Boolean
        BindDataTables = False
        Dim strStatusFilter As String = cboStatusFilter.Text

        Dim sql As String = "SELECT DISTINCT job.jobid, convert(varchar, RequestRcvdDate,101) AS RequestRcvdDate,'Log Jobs' as logjobs,'Log Boms' as logboms, " & _
            "jobcreatedby as loginname,convert(varchar, jobCreatedDate,101) AS jobCreatedDate, assignedto,convert(varchar, assigneddate,101) AS assigneddate, " & _
            "AssignedBy,convert(varchar, jobduedate,101) AS jobduedate ,rush,cus.name,sn.signname,'Attachments' as attachements, program,comments, " & _
            "com.comment as commentsdd, convert(varchar, jobopeneddate,101) AS jobopeneddate ,job.jobstatus,Jobbomstatus,copy, job.custId,TerritoryID, " & _
            "SalesPersonID,  job.units, job.EmailStatus, job.commentsdd as commentsddid, job.prepcomments, job.language " & _
            "FROM tbljob job,tblcustomer cus, tbljobbom jb, tblLookupSignName sn, tblLookupComments com " & _
            "WHERE cus.custid= job.custid AND jb.jobid=job.jobid AND job.signid=sn.signid AND jobcommited ='True' AND com.commentid= job.commentsdd AND job.JobStatus='" & cboStatusFilter.Text & "'"

        myBindingSource = New BindingSource


        da = New SqlDataAdapter()
        dtBindingAssignJobs = EstimatorSQL.PopulateAssignJobs(strStatusFilter)
        If IsNothing(dtBindingAssignJobs) Then
            Exit Function
        End If

        dtBindingAssignJobs.DefaultView.Sort = "jobid DESC"
        myBindingSource.DataSource = dtBindingAssignJobs
        DataGridView1.DataSource = myBindingSource

        BindDataTables = True

    End Function

Thanks for your help. I just don't understand why it won't clear out when I select UNASSIGNED the second time around. I bind the data, but must need to do more than that.

Thanks,
Proctor
Attached Images
   

Viewing all articles
Browse latest Browse all 27517

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>