Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

change cell to DataGridViewComboBox and populate

$
0
0

I have a DataGridView that I populate from a DataTable. I wish to change one of the cells to a datagridview ComboBox and have each rows value come from the table.    My purpose is to assure that any changes in this value comes from the populating table.    Enclosed is my code.   I would like the PayrollPeriod column type to be the combobox; the property Name to be Period, the DataSource to be a table called PayrollPeriod from a database called MastConn that is in the Server Explorer and the Display Member to be Period.   Here is the relevant code.    CompConn is a different database than MastConn.   MastConn is open and used often through out the project..

 Private Sub Employees_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim EmpAdapter As New OleDbDataAdapter("SELECT * FROM Employees WHERE Active = True ORDER BY DateLastPaid DESC", CompConn)
        Dim binding1 As New BindingSource
        Try
            EmpAdapter.Fill(dtEmp)
            Dim dtPer As New DataTable
            Dim PerAdapter As New OleDbDataAdapter("SELECT Period FROM PayrollPeriod", MastConn)
            PerAdapter.Fill(dtPer)
            sAdjustGrid()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub sAdjustGrid()
        With dgvEmp
            .Columns("SSN").Visible = False
            .Columns("LName").Width = 100
            .Columns("LName").HeaderText = "Last Name"
            .Columns("FName").Width = 90
            .Columns("FName").HeaderText = "First Name"
            .Columns("Address").Width = 120
            .Columns("City").Width = 80
            .Columns("State").Width = 30
            .Columns("State").HeaderText = "St"
            .Columns("Zip").Width = 65
            .Columns("Phone").Width = 80
            .Columns("MaritalStatus").Width = 45
            .Columns("MaritalStatus").HeaderText = "Marital Status"
            .Columns("JobPosition").Width = 100
            .Columns("JobPosition").HeaderText = "Job Position"
            .Columns("WageMethod").Width = 45
            .Columns("WageMethod").HeaderText = "Wage Method"
            .Columns("Rate").Width = 65
            .Columns("Rate").DefaultCellStyle.Format = "c2"
            .Columns("Dependents").Width = 65
            .Columns("Dependents").HeaderText = "# Dependents"
            .Columns("AdditionalWH").Width = 40
            .Columns("AdditionalWH").HeaderText = "Extra WH"
            '.Columns("PayrollPeriod").ColumnType = DataGridViewComboBoxColumn
            .Columns("PayrollPeriod").Width = 70
            .Columns("PayrollPeriod").HeaderText = "Payroll Period"


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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