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