Results 1 to 3 of 3

Thread: fill Combobox in datagridview

  1. #1
    saldo is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2012
    Posts
    1
    Reputation
    0

    fill Combobox in datagridview

    hello,
    I have a datagrid that contains two textboxes and a combobox
    I want to fill my combobox with a list of items ... compounds (these compounds related items section component that has the id of the first fields in the datagrid).
    So each row of the grid must contain:
    <id Article> <désignation Article> <list articles component>


    My code is the first two fields are bound to a dataset)
    ouvr_cnx ()
    colcombo = New DataGridViewComboBoxColumn
    DataGridView1.Columns.Add (colcombo)
    As New SqlCommand mycommand Sun ("select component from Article have designationArticle, ARTICLE_COMPOSE where (= idArticleComposant Article.idArticle And idArticleComposé =" & DataGridView1.CurrentRow.Cells (0). Value & ")", MyConnection)
    Sun mondatareader As SqlDataReader
    mondatareader = macommande.ExecuteReader
    while mondatareader.Read
    colcombo.Items.Add (mondatareader (0))
    MsgBox (mondatareader (0))
    End While
    mondatareader.Close ()
    ferm_cnx ()


    if anyone can help me ... PCQ vrm
    cordially

  2. #2
    VBobCat's Avatar
    VBobCat is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 4.0
    Join Date
    Sep 2011
    Location
    São Paulo, Brazil
    Posts
    117
    Reputation
    25
    I'd rather store my query in a datatable and then set the entire column with it this way:

    Dim MyDataTable As New DataTable
    MyDataTable.Load(mondatareader)
    Dim colcombo As New DataGridViewComboBoxColumn
    colcombo.DataSource = MyDataTable

    Hope it helps.

  3. #3
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,331
    Reputation
    1543

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking