Question : Problem with databound ComboxColumn in a Databound DatagridView. HELP :-(

Hi Dear Experts

I  have a problem with a combobox in a datagridview. Here is my VB 2008 code:

 

Dim cmd As OleDbCommand = New OleDbCommand("Select AnneDbut, CycleDbut,AnneFin, CycleFin, Quantit, Dims,Client From TTable", con)

 


Dim cmd2 As OleDbCommand = New OleDbCommand("Select AllDimensions From Dimensions", con)

con.Open()

myDA = New OleDbDataAdapter(cmd)

myDA2 = New OleDbDataAdapter(cmd2)

builder = New OleDbCommandBuilder(myDA)

builder.QuotePrefix ="["

builder.QuoteSuffix ="]"

 
myDataSet = New DataSet()

myDA.Fill(myDataSet,"MyTable")

DataGridView1.AutoGenerateColumns =True

myDataSet2 =New DataSet()

myDA2.Fill(myDataSet2,"MyDim")

 


Dim comboboxColumn As New DataGridViewComboBoxColumn

comboboxColumn.DataSource = myDataSet2.Tables("MyDim").DefaultView  'Here i fill the combobox with the content of the table DIMENSIONS

comboboxColumn.DisplayMember ="AllDimensions"

comboboxColumn.ValueMember ="AllDimensions"

comboboxColumn.Name ="Selected Dimensions"

comboboxColumn.DataPropertyName ="Dims"

DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView  'I fill the datagridview with the content of TTable

DataGridView1.Columns.Insert(5, comboboxColumn) 'I insert a column containing the combobox


con.Close()

con =

Nothing

 

Catch ex As Exception

MessageBox.Show(ex.Message)

 


End Try

My goal is  when i start the application, the datagridview will be filled with the content of the table TTable and the combobox should show the value of the column Dims of my TTable and when i click on the combobox column, it would allow me to change the value of the cell with one of the value from my Dimensions Table. My problem is that I cannot find the way to dispaly the content of the Dims column of my TTable.

Where am I wrong in my code? Could you please help me?

Thanks
MIA

Answer : Problem with databound ComboxColumn in a Databound DatagridView. HELP :-(

Keeping above comment into mind see the sample code and Images +  description in images.

 The DatagridView labeled as restructure,  has columns created manually and then filled through code.


I have attached everything four times then attachment succeeded, due to slow net connection :S
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Db2DataSet.Notes' table. You can move, or remove it, as needed.
        Me.NotesTableAdapter.Fill(Me.Db2DataSet.Notes)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGridView1.Rows.Add(Db2DataSet.Tables(0).Rows.Count)
        For i As Integer = 0 To Db2DataSet.Tables(0).Rows.Count - 1
            For j As Integer = 0 To Db2DataSet.Tables(0).Rows(i).ItemArray().Count - 1
                If j <> 1 Then
                    DataGridView1.Rows(i).Cells(j).Value = Db2DataSet.Tables(0).Rows(i).Item(j)
                Else
                    Dim c As DataGridViewComboBoxCell = New DataGridViewComboBoxCell()
                    For Each rho As DataRow In Db2DataSet.Tables(0).Rows
                        c.Items.Add(rho.Item(1))
                    Next
                    DataGridView1.Rows(i).Cells(1) = c
                End If
            Next j
        Next i
    End Sub
End Class
Random Solutions  
 
programming4us programming4us