Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB.NET
Imports System.Data.SqlClient
Imports System.Data
Imports System.Drawing
Imports System.Web.UI.WebControls


Public Class Services

    Private colCase As DataGridViewComboBoxColumn
    Private cproductTOTAL As DataGridViewTextBoxColumn

    Protected Sub Services_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'Servicesdb.Services' table. You can move, or remove it, as needed.
        Me.ServicesTableAdapter.Fill(Me.Servicesdb.Services)
        'TODO: This line of code loads data into the 'Productsdb.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.Productsdb.Products)

        colCase = New DataGridViewComboBoxColumn
        cproductTOTAL = New DataGridViewTextBoxColumn

        Dim oldValue As String = ""
        Dim con As New SqlConnection("Data Source=DESKTOP-9U3RT7R\SQLEXPRESS;Initial Catalog=Salon;Integrated Security=True")
        Dim view As New DataView

        Dim dataset As New DataSet
        Dim com As New SqlCommand


        'Dim chk As New DataGridViewCheckBoxColumn()
        'chk.HeaderText = "Select Service"
        'chk.Name = "chk"
        'Me.ServicesDataGridView.Columns.Add(chk)


    End Sub


    Private Sub servicecancelbtn_Click(sender As System.Object, e As System.EventArgs) Handles servicecancelbtn.Click
        Me.Dispose()
        ClientDetails.Show()
    End Sub

    Private cboCase As DataGridViewComboBoxEditingControl = Nothing
    Private txtproductTOTAL As DataGridViewTextBoxCell = Nothing


    Private Sub ServicesDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles ServicesDataGridView.EditingControlShowing
        'If the current cell is of the type "ComboBox"  
        If TypeOf (e.Control) Is DataGridViewComboBoxEditingControl Then
            'Cast the current cell to the temporary control  
            cboCase = DirectCast(e.Control, DataGridViewComboBoxEditingControl)
            'Cast the other cell to the other temporary control  
            txtproductTOTAL = DirectCast(ServicesDataGridView.CurrentRow.Cells(productTOTAL.Name), DataGridViewTextBoxCell)

            If cboCase IsNot Nothing Then
                'Add an EventHandler to the first temporary control  
                AddHandler cboCase.SelectedIndexChanged, AddressOf cboCase_SelectedIndexChanged
            End If
        End If
    End Sub

    Private Sub cboCase_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim con As New SqlConnection("Data Source=DESKTOP-9U3RT7R\SQLEXPRESS;Initial Catalog=Salon;Integrated Security=True")
        Dim view As New DataView
        Dim dataset As New DataSet
        Dim com As New SqlCommand

        Dim StateTable As New DataTable
        StateTable.Clear()
        Dim sqlCmd As New SqlCommand("select DISTINCT productTOTAL from Products where  productNAME='" & cboCase.Text & "'", con)
        'con.Close()
        Dim result As String
        Try
            con.Open()
            result = sqlCmd.ExecuteScalar()
            If result IsNot Nothing Then
                txtproductTOTAL.Value = result.ToString()
                'MessageBox.Show(txtState.Text)
            End If
        Catch ex As SqlException
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try

    End Sub

    Private Sub ServicesDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ServicesDataGridView.CellEndEdit
        If cboCase IsNot Nothing Then
            RemoveHandler cboCase.SelectedIndexChanged, AddressOf cboCase_SelectedIndexChanged
            cboCase = Nothing
        End If
        txtproductTOTAL = Nothing
    End Sub




    Private Sub ServicesDataGridView_CellLeave(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ServicesDataGridView.CellLeave
        Try
            Dim iCell1 As Integer
            Dim icell2 As Integer
            Dim icellResult As Integer
            iCell1 = ServicesDataGridView.CurrentRow.Cells(3).Value
            icell2 = ServicesDataGridView.CurrentRow.Cells(4).Value
            icellResult = iCell1 + icell2
            ServicesDataGridView.CurrentRow.Cells(5).Value = icellResult
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        'Make sure the selectionMode is set to cellSelect. Once user leaves the cell 3 it will get the calculated values in it.

    End Sub
   

    Protected Sub showservicesbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles showservicesbtn.Click
   
        Try
            For Each row As GridViewRow In ServicesDataGridView.SelectedRows
                Dim sum As Integer = Integer.Parse(row.Cells(5).ToString())

                'Dim chkbox As CheckBox
                'chkbox = TryCast(row.FindControl("chk"), CheckBox)
                'If chkbox.Checked Then
                '    sum = sum + row.Cells(5).Text.ToString()
                'End If


                ' If serviceselect.Selected Then
                sum = sum + Integer.Parse(row.Cells(5).ToString())

                lblmsg.Text = sum.ToString()
            Next

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Try
            Dim Data As String = "EyeBrows"
            For Each row As GridViewRow In ServicesDataGridView.SelectedRows
                If row.RowType = DataControlRowType.DataRow Then
                    Dim chkRow As CheckBox = TryCast(row.Cells(6).FindControl("chk"), CheckBox)
                    If chkRow.Checked Then
                        Dim serviceNAME As String = row.Cells(1).Text
                        Data = Convert.ToString((Data & serviceNAME) + " ,  ") + "<br>"
                    End If
                End If
            Next
            lblservices.Text = Data


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub serviceokbtn_Click(sender As System.Object, e As System.EventArgs) Handles serviceokbtn.Click

        ClientDetails.txtserviceID.Text = Me.lblservices.Text
        ClientDetails.txtappointmentTOTAL.Text = Me.lblmsg.Text

        ClientDetails.Show()
        Me.Close()
    End Sub


End Class
Posted
Updated 3-Feb-16 5:01am
Comments
Sascha Lefèvre 30-Jan-16 9:05am    
Which error and on which line?
Ashutosh Dutondkar 30-Jan-16 9:12am    
The Error is 'The Following Exception Occured in The Datagirdview. System.Arguement.Exception: DatagridviewCellCombobox value is not valid. To replace this dialog please handle the DataError Event'. After this one more error is System.IndexOutOfRangeException: Index 0 does not have value. at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(int32 rowindex)
To replace this default dialog please handle the DataError event
Ashutosh Dutondkar 30-Jan-16 9:13am    
m not getting the line on which the error is occuring but the error is which is shown above
Sascha Lefèvre 30-Jan-16 9:23am    
Which version of Visual Studio do you use?
Ashutosh Dutondkar 30-Jan-16 13:02pm    
Visual Studio 2010 Professional and SQL Server 2012

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900