I use:
Visual studio 8.0
MySql database
Two table's:
table :Groups, two fields : groupnb,groupdef
table Article,three fields : articlenb,group,articledef

I want to show with the DataGridViewComboBoxColumn two fields from groups table .
But i want only link field "articlenb" to column, but a want o show filed "Articlenb" and I want to show fields "groupnb" and "groupdef"

My question is how do this?
Here is my code for ComboBoxColumn, with one field from groups table.
This works well!

myCommand1.Connection = myConn
 myCommand1.CommandText = "SELECT * FROM article "
 myAdapter1.SelectCommand = myCommand1
 myAdapter1.Fill(MyDataTable1, "article"
DataGridView1.DataSource = MyDataTable1
'MyDataTable2
        myConn.Open()
        myCommand2.Connection = myConn
        myCommand2.CommandText = "SELECT groupnb,groupdef FROM groups order by groupnb"
        myAdapter2.SelectCommand = myCommand2
        myAdapter2.Fill(MyDataTable2)
        Dim Selectgroup As New DataGridViewComboBoxColumn
        Selectgroup.DataPropertyName = "group"
        Selectgroup.HeaderText = "group number"
        '** fill combo items
        myReader = myCommand2.ExecuteReader
           While myReader.Read
                    Selectgroep.Items.Add((myReader("groupnb")))
        End While
        DataGridView1.Columns.Add(Selectgroup)

Thanks for the reply,

Andre

>I want to show with the DataGridViewComboBoxColumn two fields from groups table . But i want only link field "articlenb" to column, but a want o show filed "Articlenb" and I want to show fields "groupnb" and "groupdef"

It's possible I misunderstood - could you please clarify?

>I want to show with the DataGridViewComboBoxColumn two fields from groups table . But i want only link field "articlenb" to column, but a want o show filed "Articlenb" and I want to show fields "groupnb" and "groupdef"

It's possible I misunderstood - could you please clarify?

Sorry about the bad english!!
I have a picture made with exactly what I want to achieve, see Annex!!!

Contact two fields in select statement.

SELECT groupnb,  groupnb + ' ' + groupdef as groupdef from TableName

Convert groupnb to varchar in case its type is numeric.

SELECT groupnb,  convret(varchar,groupnb) + ' ' + groupdef as groupdef from TableName

Contact two fields in select statement.

SELECT groupnb,  groupnb + ' ' + groupdef as groupdef from TableName

Convert groupnb to varchar in case its type is numeric.

SELECT groupnb,  convret(varchar,groupnb) + ' ' + groupdef as groupdef from TableName

I use (mysql database!)
myCommand2.CommandText = "select groupnb, CONCAT(groupnb,' ',groupdef) as groupdef from groups"
And changes:
Selectgroep.Items.Add((myReader("groupnr")))
to
Selectgroep.Items.Add((myReader("groupdef")))

the rest of the code remains the same!!
If I now run program , i get this error:

System.ArgumentException:The value is invalid datagridviewcomboBoxcell

I think we must use :
DataGridViewMultiColumnComboColumn

I must find out to use function of datagridview.
Maybe you know how to apply "DataGridViewMultiColumnComboColumn" for my particular situation

(The reason I have added to this thread is I consider it very important as there seems to be no samples anywhere, that a ComboBoxColumn is used where the Dropdown is populated from a database selection, and the Valuemember field causes the DisplayMember to show. I have been trying for a day and I still cannot get this most simple of tasks to work. In this thread's example, quite clearly, the 'groupnb' field in the 'article' dataset should cause the 'groupdef' field to display rather than the 'groupnb' number.)

I would beg to differ that the first sample of code "works". I have a complete listing here and I'm afraid it doesn't work. All it does is display the VALUEMEMBER field in the dropdown and not the DISPLAYMEMBER field and, of course, the 'article' records are not bound either (I have inserted a BindingSource control, although it seems not to have noticed it):-

'article' table
ident group articlename
----- ----- -------------
1 1 article 1
2 2 article 2
3 3 article 3

'groups' table
groupnb groupdef
------- --------
1 group1
2 group2
3 group3

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    
        Dim myCommand1   As New sqlclient.SqlCommand
        Dim myCommand2   As New SqlClient.SqlCommand
       
        Dim myConn       as New SqlClient.SqlConnection
        Dim myAdapter1   As New SqlClient.SqlDataAdapter
        Dim myAdapter2   As New SqlClient.SqlDataAdapter
        Dim myDataTable1 As New DataSet
        Dim myDataTable2 As New DataSet
        Dim myReader     As SqlClient.SqlDataReader
        Dim myBind       As New BindingSource
        
        
        myConn.ConnectionString           = "Data Source=dsffdfsdf.........."
        myCommand1.Connection             = myConn
        myCommand1.CommandText            = "SELECT * FROM article "
        myAdapter1.SelectCommand          = myCommand1
        myAdapter1.Fill(MyDataTable1, "article")
        myBind.DataSource                 = MyDataTable1
        DataGridView1.AutoGenerateColumns = True
        DataGridView1.DataSource          = myBind
        'MyDataTable2
      
        myConn.Open()
        myCommand2.Connection             = myConn
        myCommand2.CommandText            = "SELECT groupnb,groupdef FROM groups order by groupnb"
        myAdapter2.SelectCommand          = myCommand2
        myAdapter2.Fill(MyDataTable2)
         
        Dim Selectgroup As New DataGridViewComboBoxColumn
        Selectgroup.DataPropertyName      = "group"
        Selectgroup.HeaderText            = "group number"
  
       '** fill combo items
      
       myReader                           = myCommand2.ExecuteReader
       While myReader.Read
            Selectgroup.Items.Add((myReader("groupdef")))
       End While
      
       DataGridView1.Columns.Add(Selectgroup)    
     End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.