Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Datagridview Combobox

Avatar of prothera
prothera asked on
Visual Basic.NET
12 Comments1 Solution842 ViewsLast Modified:
I've created a datagridview of a table which has 3 fields. One of the fields is a boolean field. 1 - true, 0 - false. Instead of displaying 1 or 0 for the boolean field, I would like to display true or false in a combobox (in the datagridview). I've connected a combobox to a table before and linked it to the hidden ID in the datagridview. BUT, I can't figure out how to have a combobox where 1 is true and 0 is false. I'm also not using the GUI to do this. I'm doing this in code.

Any help you can give would be greatly appreciated. Here is a piece of the code. This table is a list of Machine Names (ID, Description, isActive.
----
  Private Sub frmMachinName_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '    Dim machineName As New clsDbConn
    machineName = New clsDbConn

    Me.WindowState = FormWindowState.Maximized

   'fill the dgv
    Me.BindingSource1.DataSource = machineName.GetMachineNames
    Me.dgvMachineNames.DataSource = Me.BindingSource1

    'isActive field - want to display true/false instead of 1/0 here ****
    Dim listCol As New DataGridViewComboBoxColumn
    listCol.HeaderText = "Active"
    listCol.Items.AddRange("true", "false")

    'xxx ?? how to connect the combo box to the isActive column in the dgv ???
    listCol.DisplayMember = "Description"
    listCol.ValueMember = "ID"
    Me.dgvMachineNames.Columns.Add(listCol) 'add combobox to dgv

    '3 columns in the datagridview
    Me.dgvMachineNames.Columns("MachineName_id").HeaderCell.Value = "ID" 'change the column header
    Me.dgvMachineNames.Columns("MachineName").HeaderCell.Value = "Machine Name"
    Me.dgvMachineNames.Columns("isActive").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

  End Sub


 
ASKER CERTIFIED SOLUTION
Avatar of x77
x77Flag of Spain image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answers