0

I have datagridview control and set source to datagridview and add combobox column in datagridview ,now how can i set event (selectedindexchange) combobox event to datagridview? I want when i select present then cell background color will be green and when i select absent then cell background color will be red.Please tell me how can i do this?Check screenshot link

VB.NET win forms code:

 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
don
  • 65
  • 2
  • 10
  • 1
    The CellFormatting or RowPrePaint are what you are looking for. There are not column based events because the number/type of columns is not always known at design time. So events are issued by the control with info telling you which row and column is the source – Ňɏssa Pøngjǣrdenlarp Dec 01 '17 at 17:52
  • @Plutonix thanks for response,i have done using event `DGAttendance_EditingControlShowing` and `ComboBox_SelectionChangeCommitted` – don Dec 01 '17 at 18:03

0 Answers0