Results 1 to 8 of 8

Thread: Cell Level Dynamic ComboBox Fill in DataGridView Cell

  1. #1
    Sanjoy is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2012
    Posts
    4
    Reputation
    0

    Cell Level Dynamic ComboBox Fill in DataGridView Cell

    Hi,

    I want to add a ComboBox at Cell Level in DataGrid. i. e. There is one Static ComboBox(Suppose A) in a Cell of DataGrid, upon Selecting a value of that Combo Box, there on Next cell a ComboBox(Suppose B) will generate dynamically. My Problem is that, on first Row of Grid B ComboBox Value Changes to The value Of Current Row(When Adding a Differrent Value on 2nd Row). My Dynamic ComboBox Generation Code is Following:

    Code:
        Private Sub dgvValue_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvValue.CellEndEdit
    
    
            Select Case e.ColumnIndex
    
                Case A
                    Dim dgvCboB As New DataGridViewComboBoxCell
                    DT_B = FetchDatatable(dgvValue(A, e.RowIndex).EditedFormattedValue)
                    dgvCboB.DataSource = DT_B
                    dgvCboB.DisplayMember = "Value Name"
                    dgvCboB.ValueMember = "GUID"
                    dgvCboB.AutoComplete = True
                    dgvValue(B, e.RowIndex) = dgvCboB
            End Select
         End Sub
    Last edited by Sanjoy; 03-20-2012 at 7:49 AM.

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

  3. #3
    Sanjoy is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2012
    Posts
    4
    Reputation
    0
    Like First is For Country and Second is for State

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,504
    Reputation
    1553
    That doesn't answer the question. That doesn't require you to create DataGridViewComboBoxCells on demand. You can just add two DataGridViewComboBoxColumns to your grid as you normally would. The only difference would be that you would either rebind or filter the data source of the cell in the State column when the cell in the Country column of the same row had its Value set.

  5. #5
    Sanjoy is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2012
    Posts
    4
    Reputation
    0
    How to rebind the data of State when the Country value is set? that should take effect only in that row.

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,504
    Reputation
    1553
    Handle the CellValueChanged event of the grid. Test e.ColumnIndex to see if the change was in the Country column. If it was, use e.RowIndex to get the row. Get the Value from the cell in the Country column and use that to get the appropriate state data and assign that to the DataSource of the cell in the State column.

  7. #7
    Sanjoy is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2012
    Posts
    4
    Reputation
    0
    In CellValueChanged event still cells are modified for other rows except the selected row for State column.

  8. #8
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,504
    Reputation
    1553
    I don't really understand what you just posted but I assume that you're saying that it doesn't work. In that case you're doing it wrong. As we can't see what you're doing, we can't see what's wrong with it.

Tags for this Thread

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