如何在datagrodview combox列中添加selectedindexchange事件?VB.NET winForms

时间:2017-12-01 17:08:13

标签: .net vb.net winforms datagridview

我有datagridview控件并将源设置为datagridview并在datagridview中添加了组合框列,现在我如何将事件(selectedindexchange)组合框事件设置为datagridview? 我希望当我选择present时,单元格背景颜色为green,当我选择absent时,单元格背景颜色为red。请告诉我该怎么做?查看截图link

VB.NET win表单代码:

 Dim query = "Select    E.employee_id Employee_ID ,E.full_name Name,JI.Designitation "
    query = query & " From  Employee E"
    query = query & " Inner Join Employee_Job_Info JI On E.employee_id = JI.Emp_ID"
    query = query & " WHERE JI.Department='" & ComboBox1.SelectedValue.ToString() & "'"
    Dim dt As DataTable
    dt = getDataTable(query)
    DGAttendance.DataSource = dt

    If DGAttendance.Columns.Count <= 3 Then
        Dim col As New DataGridViewComboBoxColumn
        DGAttendance.Columns.Add(col)

        col.DataPropertyName = "Att_Status"
        col.HeaderText = "Status"
        col.Name = "Attedence_Status"
        col.Items.Add("Present")
        col.Items.Add("Absent")
        col.Items.Add("Leave")
        col.DefaultCellStyle.BackColor = Color.Red
        col.DefaultCellStyle.ForeColor = Color.White


    End If

0 个答案:

没有答案