DataGridView with dropdown column

1.2k views Asked by At

I got back to VB.NET after being some years abstinent to VB. Offcourse you can do everything with the designer, but.

I want to implement database functionalities by code. I have a DataGridView which will be filled like I expect. Changes will be safed, ok for now.

But I'd like to change the field which represents an foreignkey value to a dropdown field. I tried by myself and searched for a good solution, but nothing found.

This is part of my code:

.AutoGenerateColumns = True
        .DataSource = TMitarbeiterBindingSource
        .AutoSizeRowsMode = _
            DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
        .BorderStyle = BorderStyle.Fixed3D
        .EditMode = DataGridViewEditMode.EditOnEnter

There a six columns and I want the third to be a dropdown field which should use another BindingSource. Propably I have to change AutoGenerateColumns to false, but then how to add the columns manually. And after that I have to change one of the columns, but how?

If anybody would have an example that fits with my code would be helpful.

1

There are 1 answers

0
pia-sophie On

I got it, I used the following code and it works:

 With rufnummer
            .DataPropertyName = "Rufnummer"
            .DataSource = db.TGeraeteBindingSource
            .DisplayMember = "Rufnummer"
            .ValueMember = "Rufnummer"
            .FlatStyle = System.Windows.Forms.FlatStyle.Flat
            .HeaderText = "Rufnummer"
            .Width = 70
        End With