Hi,

I'm current working on a project that allows the user to store customer and job details. At the min, I have a form to view and add customer records, but also edit/delete etc. customer records. I also have a form to add a particular job type. I'm working on the form to view these jobs and this is where the trouble started....

for any job, it can be saved as a quote or job, and later tagged as completed.

In the form for viewing the job, I have
-- a dataset for customer records and job records.
-- A combo box with a list of all customers. when a customer is selected
-- a datagridview is updated to display all jobs related to the selected customer. I done this using a dataview and dataview.rowfilter and it works fine.
-- when a row is selected in the datagridview, all the job details are displayed below in textboxes.

I have a button to convery quote to job, and job to completed. The problem is when I try to modify the current displayed record, it only updates the very first record (position 0) :confused:

Theres quite a bit of code, sorry but if anyone wants to look at it to try and help just let me know - I'm not looking someone to do my code, even just a few pointers if I'm even doing this the right way!!

Imports System.Data
Imports System.Data.OleDb

'----------------------------------------------------------------------------------------
' Module        : 
' Project       : CDiTNi
' Version       : 1.1
' Date          : 
' Author        : Stephen Cassidy
' Description   : 
'----------------------------------------------------------------------------------------
Public Class frmViewDataRecoveryJobs
    '####################### Module Level Constants and Variables ###########################
    Dim dsDataRecoveryJobs As New DataSet

    Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\HND Computing\Year 2\Assignments\SDP1\CDiTNi\CDiTNi.accdb"
    Dim connOle As New OleDbConnection
    Dim daCustomers As New OleDbDataAdapter
    Dim daDataRecoveryJobs As New OleDbDataAdapter

    Dim dbCustomerJobRelation As DataRelation
    Dim dvCustomerJob As DataView
    Dim rvRowView As DataRowView
    Dim dcParent As DataColumn
    Dim dcChild As DataColumn

    Dim bsDataRecoveryJobs As New BindingSource
    Dim commandBuilder As New OleDbCommandBuilder
    '########################################################################################



    '##################################################################### Load Event #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : frmViewDataRecoveryJobs_Load
    ' Date          : 04/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub frmViewDataRecoveryJobs_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.connOle.ConnectionString = Me.connStr

        Me.daDataRecoveryJobs = New OleDbDataAdapter("SELECT DataRecoveryJobID, StaffID, CustomerID, [DateCreated], 
[Make], SerialNumber, Problem, FormatPCPermission, 
BackupData, DataToBeBackedUp, UsernamePasswords, [AdditionalRequests], 
[AdditionalHardwareSoftware], [EstimatedJobTimeDays], [TotalCost], [Quote], [Completed], 
[DateCompleted] FROM tblJobsDataRecovery", connOle)

        Me.daCustomers = New OleDbDataAdapter("SELECT * FROM tblCustomerAccounts", connOle)

        Me.daDataRecoveryJobs.Fill(Me.dsDataRecoveryJobs, "tblJobsDataRecovery")
        Me.daCustomers.Fill(Me.dsDataRecoveryJobs, "tblCustomerAccounts")

        Me.dcParent = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Columns("CustomerID")
        Me.dcChild = Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery").Columns("CustomerID")
        Me.dbCustomerJobRelation = New DataRelation("CustomerJob", Me.dcParent, Me.dcChild)
        Me.dsDataRecoveryJobs.Relations.Add(Me.dbCustomerJobRelation)


        Me.commandBuilder = New OleDbCommandBuilder(Me.daDataRecoveryJobs)
        Me.bsDataRecoveryJobs.DataSource = Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery")

        Me.txtDataRecoveryJobID.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "DataRecoveryJobID", True))
        Me.txtCustomerID.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "CustomerID", True))
        Me.txtStaffID.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "StaffID", True))
        Me.txtDateCreated.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "DateCreated", True))
        Me.txtMake.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "Make", True))
        Me.txtSerialNumber.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "SerialNumber", True))
        Me.txtProblem.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "Problem", True))
        Me.chkFormatPCPermission.DataBindings.Add(New Binding("Checked", Me.bsDataRecoveryJobs, "FormatPCPermission", True))
        Me.chkBackupData.DataBindings.Add(New Binding("Checked", Me.bsDataRecoveryJobs, "BackupData", True))
        Me.txtDataToBeBackedUp.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "DataToBeBackedUp", True))
        Me.txtUsernamePasswords.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "UsernamePasswords", True))
        Me.txtAdditionalRequests.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "AdditionalRequests", True))
        Me.txtAdditionalHardwareSoftware.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "AdditionalHardwareSoftware", True))
        Me.txtEstimatedJobTimeDays.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "EstimatedJobTimeDays", True))
        Me.txtTotalCost.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "TotalCost", True))
        Me.chkQuote.DataBindings.Add(New Binding("Checked", Me.bsDataRecoveryJobs, "Quote", True))
        Me.chkCompleted.DataBindings.Add(New Binding("Checked", Me.bsDataRecoveryJobs, "Completed", True))
        Me.txtDateCompleted.DataBindings.Add(New Binding("Text", Me.bsDataRecoveryJobs, "DateCompleted", True))

        With Me.cboCustomers
            .DataSource = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts")
            .DisplayMember = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Columns("CustomerID").ToString()
            .ValueMember = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Columns("CustomerID").ToString()
            .SelectedIndex = 0
        End With

        ' set properties of buttons
        With Me.btnUpgradeToJob
            .FlatStyle = FlatStyle.Flat
            .FlatAppearance.MouseDownBackColor = Color.RoyalBlue
            .FlatAppearance.MouseOverBackColor = Color.SteelBlue
        End With

        With Me.btnCompleteJob
            .FlatStyle = FlatStyle.Flat
            .FlatAppearance.MouseDownBackColor = Color.RoyalBlue
            .FlatAppearance.MouseOverBackColor = Color.SteelBlue
        End With

        With Me.btnCancelJob
            .FlatStyle = FlatStyle.Flat
            .FlatAppearance.MouseDownBackColor = Color.RoyalBlue
            .FlatAppearance.MouseOverBackColor = Color.SteelBlue
        End With

        With Me.btnClose
            .FlatStyle = FlatStyle.Flat
            .FlatAppearance.MouseDownBackColor = Color.RoyalBlue
            .FlatAppearance.MouseOverBackColor = Color.SteelBlue
        End With

        ResetFilters()
        DisableEditing()
        EnableButtons()



    End Sub



   '##################################################################### DataGrids #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : dgDataRecoveryJobs_SelectionChanged
    ' Date          : 04/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub dgDataRecoveryJobs_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDataRecoveryJobs.SelectionChanged
        'Update DataGrid Colours
        SetDataGridRowColour()
        EnableButtons()

        ' Display Job details in textboxes
        Me.txtDataRecoveryJobID.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.bsDataRecoveryJobs.Position).Cells.Item("DataRecoveryJobID").Value.ToString()
        Me.txtCustomerID.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("CustomerID").Value.ToString()
        Me.txtStaffID.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("StaffID").Value.ToString()
        Me.txtDateCreated.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("DateCreated").Value.ToString()
        Me.txtMake.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Make").Value.ToString()
        Me.txtSerialNumber.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("SerialNumber").Value.ToString()
        Me.txtProblem.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Problem").Value.ToString()
        Me.chkFormatPCPermission.Checked = CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("FormatPCPermission").Value)
        Me.chkBackupData.Checked = CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("BackupData").Value)
        Me.txtDataToBeBackedUp.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("DataToBeBackedUp").Value.ToString()
        Me.txtUsernamePasswords.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("UsernamePasswords").Value.ToString()
        Me.txtAdditionalRequests.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("AdditionalRequests").Value.ToString()
        Me.txtAdditionalHardwareSoftware.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("AdditionalHardwareSoftware").Value.ToString()
        Me.txtEstimatedJobTimeDays.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("EstimatedJobTimeDays").Value.ToString()
        Me.txtTotalCost.Text = "£" & Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("TotalCost").Value.ToString()
        Me.chkQuote.Checked = CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Quote").Value)
        Me.chkCompleted.Checked = CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Completed").Value)
        Me.txtDateCompleted.Text = Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("DateCompleted").Value.ToString()
    End Sub



    '##################################################################### Buttons #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : btnUpgradeToJob_Click
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub btnUpgradeToJob_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpgradeToJob.Click
        Try
            If MessageBox.Show("Confirm Quote As Job?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
            MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

                MessageBox.Show(Me.bsDataRecoveryJobs.Position.ToString())
                MessageBox.Show(Me.dgDataRecoveryJobs.CurrentRow.Index.ToString())
                MessageBox.Show(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery").Rows.Count.ToString)

                Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery").Rows(Me.bsDataRecoveryJobs.Position)("Quote") = False

                ' Update Database and display confirmation message
                Me.bsDataRecoveryJobs.EndEdit()
                Me.daDataRecoveryJobs.Update(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

                MessageBox.Show("CDiTNi Database Updated Sucessfully", "Update Successful", MessageBoxButtons.OK, _
                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)

            Else ' Else if user selects 'No'
                'Do Nothing
            End If ' End of 'Confirm Quote As Job?' If

        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

        Finally
            EnableButtons()
        End Try ' End of Main Try Catch
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : btnCompleteJob_Click
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub btnCompleteJob_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompleteJob.Click
        Try
            If MessageBox.Show("Tag Job As Completed?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
                        MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

                ' Set Completed to "True"
                Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery").Rows(Me.dgDataRecoveryJobs.CurrentRow.Index)("Completed") = True
                Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery").Rows(Me.dgDataRecoveryJobs.CurrentRow.Index)("DateCompleted") = Today.ToShortDateString()

                ' Update Database and display confirmation message
                Me.bsDataRecoveryJobs.EndEdit()
                Me.daDataRecoveryJobs.Update(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

                MessageBox.Show("CDiTNi Database Updated Sucessfully", "Update Successful", MessageBoxButtons.OK, _
                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)

            Else ' Else if user selects 'No'
                'Do Nothing
            End If ' End of 'Tag Job As Completed?' If

        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

        Finally
            EnableButtons()
        End Try ' End of Main Try Catch
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : btnCancelJob_Click
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub btnCancelJob_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelJob.Click
        Try

        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

        Finally
            EnableButtons()
        End Try ' End of Main Try Catch
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : btnClose_Click
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Try
            If MessageBox.Show("Close?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
            MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

                frmMenu.Show() ' Show Menu Form
                Me.Close() ' Close current form
            End If ' End of Main If
        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
        End Try ' End of Main Try Catch
    End Sub



    '##################################################################### CheckBoxes #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : chkShowQuotes_CheckedChanged
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub chkShowQuotes_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkShowQuotes.CheckedChanged
        '####################### Procedure Level Constants and Variables ###########################
        ' Dim dvJob As DataView = DataView used to filter the DataGrid 
        Dim dvJob As DataView
        '###########################################################################################

        dvJob = New DataView(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

        If CBool(Me.chkShowQuotes.Checked) = True Then

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "' AND Quote = 'True' AND Completed = 'False'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        Else

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        End If
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : chkShowJobs_CheckedChanged
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub chkShowJobs_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkShowJobs.CheckedChanged
        '####################### Procedure Level Constants and Variables ###########################
        ' Dim dvJob As DataView = DataView used to filter the DataGrid 
        Dim dvJob As DataView
        '###########################################################################################

        dvJob = New DataView(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

        If CBool(Me.chkShowJobs.Checked) = True Then

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "' AND Quote = 'False' AND Completed = 'False'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        Else

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        End If
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : chkShowCompleted_CheckedChanged
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub chkShowCompleted_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkShowCompleted.CheckedChanged
        '####################### Procedure Level Constants and Variables ###########################
        ' Dim dvJob As DataView = DataView used to filter the DataGrid 
        Dim dvJob As DataView
        '###########################################################################################

        dvJob = New DataView(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

        If CBool(Me.chkShowCompleted.Checked) = True Then

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "' AND Completed = 'True'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        Else

            dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "'"
            Me.dgDataRecoveryJobs.DataSource = dvJob
            Me.dgDataRecoveryJobs.Refresh()

        End If
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : chkShowAllJobs_CheckedChanged
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub chkShowAllJobs_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkShowAllJobs.CheckedChanged
        '####################### Procedure Level Constants and Variables ###########################
        ' Dim dvJob As DataView = DataView used to filter the DataGrid 
        Dim dvJob As DataView
        '###########################################################################################

        dvJob = New DataView(Me.dsDataRecoveryJobs.Tables("tblJobsDataRecovery"))

        Me.chkShowQuotes.CheckState = CheckState.Unchecked
        Me.chkShowJobs.CheckState = CheckState.Unchecked
        Me.chkShowCompleted.CheckState = CheckState.Unchecked

        dvJob.RowFilter = "CustomerID = '" & Me.cboCustomers.SelectedValue.ToString() & "'"
        Me.dgDataRecoveryJobs.DataSource = dvJob
        Me.dgDataRecoveryJobs.Refresh()

    End Sub



    '##################################################################### ComboBoxes #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : cboCustomers_SelectedIndexChanged
    ' Date          : 04/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub cboCustomers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCustomers.SelectedIndexChanged

        Try

            Me.dvCustomerJob = New DataView(Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts"))

            ' Display Customer Details
            Me.txtCustomerName.Text = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custFirstName").ToString() _
            & " " & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custSurname").ToString()

            Me.txtCustomerAddress.Text = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custAddressLine1").ToString() _
            & Environment.NewLine() & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custAddressLine2").ToString() _
            & Environment.NewLine() & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custCityTown").ToString() _
            & Environment.NewLine() & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custPostCode").ToString()

            Me.txtCustomerContactDetails.Text = Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custContactNumber").ToString() _
            & Environment.NewLine() & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custMobileNumber").ToString() _
            & Environment.NewLine() & Me.dsDataRecoveryJobs.Tables("tblCustomerAccounts").Rows(Me.cboCustomers.SelectedIndex)("custEmail").ToString()

            ' Update DataGrid view
            Me.rvRowView = Me.dvCustomerJob(Me.cboCustomers.SelectedIndex)
            Me.dgDataRecoveryJobs.DataSource = Me.rvRowView.CreateChildView(Me.dbCustomerJobRelation)
            ' Set DataGrid properties
            SetDataGridProperties()

        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

        Finally
            ResetFilters()
        End Try

    End Sub


    '##################################################################### Custom Procedures #########################################################################
    '----------------------------------------------------------------------------------------
    ' Procedure     : SetDataGridRowColour
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : Changes the colour of the datagrid row depending on whether the selected
    '                 job is a quote, job, or completed.
    '----------------------------------------------------------------------------------------
    Private Sub SetDataGridRowColour()

        For Each drDataGridRow As DataGridViewRow In Me.dgDataRecoveryJobs.Rows
            ' If 'Quote' in the current row equals 'True', set selection colour to Red
            If CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Quote").Value) = True Then
                Me.dgDataRecoveryJobs.CurrentRow.DefaultCellStyle.BackColor = Color.LightGray
            End If
            ' If 'Quote' in the current row equals 'False', set selection colour to DimGray
            If CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Quote").Value) = False Then
                Me.dgDataRecoveryJobs.CurrentRow.DefaultCellStyle.BackColor = Color.DimGray
            End If
            ' If 'Completed' in the current row equals 'True', set selection colour to Tan
            If CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Completed").Value) = True Then
                Me.dgDataRecoveryJobs.CurrentRow.DefaultCellStyle.BackColor = Color.Tan
            End If
        Next
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : SetDataGridProperties
    ' Date          : 04/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub SetDataGridProperties()
        With Me.dgDataRecoveryJobs
            ' Setting properties of DataGird
            .ReadOnly = True
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
            .MultiSelect = False
            .SelectionMode = DataGridViewSelectionMode.CellSelect
            .ScrollBars = ScrollBars.Vertical

            ' Setting properties of columns that will be displayed
            With .Columns("DataRecoveryJobID")
                .HeaderText = "DRID"
                .FillWeight = 100
                .Resizable = DataGridViewTriState.False
            End With

            With .Columns("EstimatedJobTimeDays")
                .HeaderText = "Est. Time (Days)"
                .FillWeight = 75
                .Resizable = DataGridViewTriState.False
            End With

            With .Columns("DateCreated")
                .HeaderText = "Date Created"
                .FillWeight = 80
                .Resizable = DataGridViewTriState.False
            End With

            With .Columns("TotalCost")
                .HeaderText = "Total Cost"
                .FillWeight = 75
                .Resizable = DataGridViewTriState.False
            End With

            With .Columns("Completed")
                .HeaderText = "Completed?"
                .FillWeight = 75
                .Resizable = DataGridViewTriState.False
            End With

            With .Columns("DateCompleted")
                .HeaderText = "Date Completed"
                .FillWeight = 75
                .Resizable = DataGridViewTriState.False
            End With

            'Columns to be hidden
            .Columns("CustomerID").Visible = False
            .Columns("StaffID").Visible = False
            .Columns("Make").Visible = False
            .Columns("SerialNumber").Visible = False
            .Columns("Problem").Visible = False
            .Columns("FormatPCPermission").Visible = False
            .Columns("BackupData").Visible = False
            .Columns("DataToBeBackedUp").Visible = False
            .Columns("UsernamePasswords").Visible = False
            .Columns("AdditionalRequests").Visible = False
            .Columns("AdditionalHardwareSoftware").Visible = False
            .Columns("Quote").Visible = False
        End With
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : DisableEditing
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : 
    ' Description   : 
    '----------------------------------------------------------------------------------------
    Private Sub DisableEditing()

        ' set ReadOnly to True for textboxes/Checkboxes in GroupBox gbxCustomerDetails
        Me.txtCustomerName.ReadOnly = True
        Me.txtCustomerAddress.ReadOnly = True
        Me.txtCustomerContactDetails.ReadOnly = True

        ' set ReadOnly to True for textboxes/Checkboxes in GroupBox gbxJobDetails
        Me.txtMake.ReadOnly = True
        Me.txtSerialNumber.ReadOnly = True
        Me.txtProblem.ReadOnly = True
        Me.chkFormatPCPermission.Enabled = False
        Me.chkBackupData.Enabled = False
        Me.txtDataToBeBackedUp.ReadOnly = True
        Me.txtUsernamePasswords.ReadOnly = True
        Me.txtAdditionalRequests.ReadOnly = True
        Me.txtAdditionalHardwareSoftware.ReadOnly = True

        ' set ReadOnly to True for textboxes/Checkboxes in GroupBox gbxTimeCost
        Me.txtEstimatedJobTimeDays.ReadOnly = True
        Me.txtTotalCost.ReadOnly = True
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : ResetFilters
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : None
    ' Description   : Resets the checkboxes to their defaults (false)
    '----------------------------------------------------------------------------------------
    Private Sub ResetFilters()
        Me.chkShowQuotes.Checked = False
        Me.chkShowJobs.Checked = False
        Me.chkShowCompleted.Checked = False
        Me.chkShowAllJobs.Checked = False
    End Sub

    '----------------------------------------------------------------------------------------
    ' Procedure     : EnableButtons
    ' Date          : 06/03/2010
    ' Author        : Stephen Cassidy
    ' Parameters    : None
    ' Description   : Enables or disables the Upgrade To Job, Complete job and 
    '                 Cancel Quote / Job buttons depending on the type of job selected
    '----------------------------------------------------------------------------------------
    Private Sub EnableButtons()

        ' if Completed = True
        If CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Completed").Value) = True Then
            ' Disable all buttons
            Me.btnUpgradeToJob.Enabled = False
            Me.btnCancelJob.Enabled = False
            Me.btnCompleteJob.Enabled = False

            ' if Quote = True
        ElseIf CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Quote").Value) = True Then
            ' Enable btnUpgradeToJob and btnCancelJob to allow user to convery quote to job, or cancel quote
            Me.btnUpgradeToJob.Enabled = True
            Me.btnCancelJob.Enabled = True

            ' Disable btnCompleteJob
            Me.btnCompleteJob.Enabled = False

            ' Else if Quote = False
        ElseIf CBool(Me.dgDataRecoveryJobs.Rows.Item(Me.dgDataRecoveryJobs.CurrentRow.Index).Cells.Item("Quote").Value) = False Then
            ' Disable btnUpgradeToJob 
            Me.btnUpgradeToJob.Enabled = True

            ' Enable btnCompleteJob and btnCancelJob to allow user to complete job or cancel it
            Me.btnCancelJob.Enabled = True
            Me.btnCompleteJob.Enabled = True
        End If ' End of Main if

    End Sub




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(Me.dgDataRecoveryJobs.CurrentRow.Index.ToString())
    End Sub
End Class

Edited 6 Years Ago by SCass2010: Tidying up code

>The problem is when I try to modify the current displayed record, it only updates the very first record (position 0)

Look at Line #133 (selection event/method)
You are replacing (bounded control value) the first record with selected rows.

Hmmmm I think I understand what your saying, I think I've just done the whole thing wrong and I've been adding so many things in trying to get it too work that I haven't a clue what I'm doing anymore :icon_confused:

This article has been dead for over six months. Start a new discussion instead.