Results 1 to 8 of 8

Thread: [RESOLVED] Populate datagridview combobox based on index

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: Populate datagridview combobox based on index

    Quote Originally Posted by wes4dbt View Post
    Are you having trouble retrieving the store index or displaying the information in the CB, or both.

    One thing you need to know is a DGV comboBox column does not have a SelectedIndex or SelectedValue property that you can set. You must set the dgv.row(someRow).Cells(somecolumn).Value = "something"

    Here a good link, http://stackoverflow.com/questions/2...ridview-vb-net
    I am having trouble displaying the information in the CB. I can retrieve the data fine, just can't populate the combobox using the index.

    Is there a way around not having a selectedindex? Would using ENUM work? (not really sure how to do this either!)

    I will take a look at the link. Thank you.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: Populate datagridview combobox based on index

    Quote Originally Posted by Chrissy View Post
    I am having trouble displaying the information in the CB. I can retrieve the data fine, just can't populate the combobox using the index.

    Is there a way around not having a selectedindex? Would using ENUM work? (not really sure how to do this either!)

    I will take a look at the link. Thank you.
    I figured it out... here is my code for future reference.

    Code:
            Dim db As New DataAccess.sqlDataBase("hp_accting")
            
            Try
                dtgAllocation.Columns.Add("Description", "Taxable Income/(Loss)")
    
                Dim reader As SqlClient.SqlDataReader = db.GetRecords("Tax_allocation", , , "allocation_code")
    
                While reader.Read
                    dtgAllocation.Rows.Add(reader.Item("allocation_name"))
                    xRow = xRow + 1
                End While
    
                reader.Close()
                dtgAllocation.Update()
    
                reader = db.GetRealtedRecords("ownership o", "partner p", "p.ocode", "o.ocode",
                                                    "p.name, o.ocode", "Tax_projection = '" & cmbYear.Text &
                                                    "' AND entity_num = '" & cmbEntity.Text.Substring(0, 8).Trim & "'", "p.ocode")
                'This loads the partner
                If reader.HasRows Then
    
                    While reader.Read
                        xColCount = xColCount + 1
                        Dim cmb As New DataGridViewComboBoxColumn()
                        cmb.Name = reader.Item("ocode").ToString
                        cmb.HeaderText = reader.Item("name")
                        cmb.MaxDropDownItems = 3
                        'Got rid of value member in order to use "Item"
                        cmb.Items.Add("Direct")
                        cmb.Items.Add("Indemnification")
                        cmb.Items.Add("Other")
                        dtgAllocation.Columns.Add(cmb)
                        xRow = 0
    
                        dtgAllocation.Update()
    
                        Dim dbPop As New DataAccess.sqlDataBase("hp_accting")
                        Dim readerPop As SqlClient.SqlDataReader = dbPop.GetRecords("tax_Owner_Allocations", , "projection_year = '" & cmbYear.Text &
                                "' AND ocode = '" & reader.Item("ocode").ToString &
                                "' AND entity_num = '" & cmbEntity.Text.Substring(0, 8).Trim & "'", "allocation_code")
    
                        If readerPop.HasRows Then
                            While readerPop.Read
    
                                dtgAllocation.Rows(xRow).Cells(xColCount).Value = cmb.Items(readerPop.Item("percent_type"))
                                xRow = xRow + 1
    
                            End While
    
                        End If
                        dbPop = Nothing
                        readerPop = Nothing
                    End While
    
                End If
    
                reader.Close()
                dtgAllocation.Update()

Posting Permissions

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



Click Here to Expand Forum to Full Width