-1

I want to bind the value of cells in one column to another column in a datagridview. The 1st column is Team and the other is Assignment. I want to set the the selected value (Assignment.Value; teamComboBox.ValueMember ) = (Team.Value; row.Cells.Item(6)) after the dgv is loaded.

This is what I have so far:

   Dim conn As New SqlConnection(My.Resources.FCLRptConn)
        Dim cmd As New SqlCommand("spFCLLUVTeamAssignment", conn)
        Dim da As New SqlDataAdapter(cmd)
        Dim TeamAssign As New DataTable

        da.Fill(TeamAssign)

        With FCLTeam
            .DataPropertyName = "FCLTeam"
            .Name = "FCLTeam"
            .DataSource = TeamAssign
            .DisplayMember = "FCLTeamName"
            .ValueMember = "FCLTeamID"
            .AutoSizeMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
            .DisplayIndex = 6

        End With

I now have 2 columns appearing in the DGV. One is from the dataset and the other is the datagridcomboboxcolumn that I added.

How would I show only the datagridcomboboxcolumn ?

ghost_king
  • 870
  • 2
  • 12
  • 24

1 Answers1

2

Unless there are very specific reasons not to, you can bind the two columns to the same field value.

If that doesn't work for you please add additional details on your requirements.

EDIT:

You must use DataGridViewComboBoxColumn and set its ValueMember and DisplayMember on the appropriate field names. ValueMember usually is the key field of the data source used to populate the combobox.

Once this is set correctly you won't need to loop through your grid rows. Binding will take care of matching the appropriate combobox element.

Crono
  • 10,211
  • 6
  • 43
  • 75
  • Well I first load a dgv and then add a combobox column. I want to match the value of one of the columns to the combobox column to load a value from the dropdown... – ghost_king Feb 26 '14 at 15:31
  • If I understand clearly then this sounds rather straightforward. Try editing your question with what you've tried so far and what precise challenges you are meeting. This should help you getting more attention to your post. – Crono Feb 26 '14 at 15:35
  • So what you are saying is after loading the datagridview and then inserting the DataGridViewComboBoxColumn I should bind the valuemember of the other column? – ghost_king Feb 26 '14 at 18:23
  • I'm not sure why you even need to insert the column after loading the data to begin with. For the rest, I suggest you take a look at the DataGridViewComboBoxColumn documentation (see link). This will be far better place to start. – Crono Feb 26 '14 at 18:25
  • Why would that make a difference on your UI design? – Crono Feb 26 '14 at 18:27
  • It might be the terms you are using or me not seeing clearly, but from where I stand you are missing some basic knowledge on how datagrid and general binding works. This makes it impossible for me to help you any further. Sorry. – Crono Feb 26 '14 at 21:48
  • Ok this is what I did. I added the DatGridViewComboBoxColumn to the DGV designer and loaded it with the necessary dropdown values. I then set the valuemember and display member on the appropriate field names and it loaded exactly how I needed it to be. The next step would be to update the field members when they are changed in the DGV like the dropdown values... – ghost_king Mar 02 '14 at 21:20