I am using vb.net visual studio 2010
I have two comboboxes in the datagrid - one for Country and the other for State Province.
Obviously the Country combo box controls what state/provinces to display.
The trouble for rows with different countries - when the user is changing the state for one country - the other states remain blank until the user sets focus somewhere else - if they don't it looks like the state information on the grid has vanished
what to do?

''' <summary>
    ''' http://www.daniweb.com/software-development/csharp/threads/80084
    ''' http://bytes.com/topic/visual-basic-net/answers/660909-get-value-cell-datagridview
    ''' http://www.java2s.com/Code/VB/Database-ADO.net/UseFiltertofilterDataTable.htm
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub addressDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles addressDataGridView.CellBeginEdit
        If addressDataGridView.Columns(e.ColumnIndex).Name = "stprv_cd" Then
            Dim dt As New DataTable
            dt = ds2.Tables("stateprv").Clone
            ' 2. Set display filter

            Dim filter1 As String = "rel_id = 'CA'"         ' addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString
            Select Case addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString
                Case "CA", "US"
                    filter1 = "rel_id = '" & addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString & "'"
                Case Else
                    filter1 = "rel_id = ' '"
            End Select


            ' 3. Set sort
            Dim sort1 As String = "display"
            dt = ds2.Tables("stateprv").Select(filter1, sort1).CopyToDataTable
            Dim col As DataGridViewComboBoxColumn
            col = CType(addressDataGridView.Columns("stprv_cd"), DataGridViewComboBoxColumn)
            col.DataSource = dt
            col.DisplayMember = "display"
            col.ValueMember = "value"

        End If

    End Sub

 ''' <summary>
    ''' http://www.vbdotnetforums.com/winforms-grids/11313-setting-cell-focus-datagridview.html
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub addressDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles addressDataGridView.CellEndEdit
        
            If addressDataGridView.Columns(e.ColumnIndex).Name = "stprv_cd" Then
                'needed because initial retreive did not fire country combo box to load state
                '    lookupstprvBindingSource.DataSource = lookupcountryBindingSource
                '    lookupstprvBindingSource.DataMember = "CSP"
                Dim dt As New DataTable
                dt = ds2.Tables("stateprv").Copy
                Dim col As DataGridViewComboBoxColumn
                col = CType(addressDataGridView.Columns("stprv_cd"), DataGridViewComboBoxColumn)
                col.DataSource = dt
                col.DisplayMember = "display"
                col.ValueMember = "value"
         

            End If


    End Sub

hi rustyone, I had same problem as you with my filtered combobox column appearing blank on the non current rows, then once the user clicked away from the combo box the values reapeared.

I solved this by using the example code (in c# but easily converted using an online tool) found on this thread http://www.daniweb.com/software-development/csharp/threads/285966 :

DataTable tblPrimary, tblSecondary;
        BindingSource primaryBS, filteredSecondaryBS, unfilteredSecondaryBS;
        
        public Form1()
        {

            tblPrimary <strong class="highlight">=</strong> new DataTable("Primary");
            tblPrimary.Columns.Add("ID", typeof(int));
            tblPrimary.Columns.Add("Name", typeof(string));

            tblSecondary <strong class="highlight">=</strong> new DataTable("Secondary");
            tblSecondary.Columns.Add("ID", typeof(int));
            tblSecondary.Columns.Add("subID", typeof(int));
            tblSecondary.Columns.Add("Name", typeof(string));

            tblPrimary.Rows.Add(new object[] { 0, "Force" });
            tblPrimary.Rows.Add(new object[] { 1, "Torque" });
            tblPrimary.Rows.Add(new object[] { 2, "Pressure" });

            tblSecondary.Rows.Add(new object[] { 0, 0, "lb" });
            tblSecondary.Rows.Add(new object[] { 1, 0, "N" });
            tblSecondary.Rows.Add(new object[] { 2, 0, "oz" });
            tblSecondary.Rows.Add(new object[] { 3, 1, "in-lb" });
            tblSecondary.Rows.Add(new object[] { 4, 1, "ft-lb" });
            tblSecondary.Rows.Add(new object[] { 5, 1, "N-m" });
            tblSecondary.Rows.Add(new object[] { 6, 2, "PSI" });
            tblSecondary.Rows.Add(new object[] { 7, 2, "Pa" });
            tblSecondary.Rows.Add(new object[] { 8, 2, "bar" });
            
            InitializeComponent();

            primaryBS <strong class="highlight">=</strong> new BindingSource();
            primaryBS.DataSource <strong class="highlight">=</strong> tblPrimary;
            primaryComboBoxColumn.DataSource <strong class="highlight">=</strong> primaryBS;
            primaryComboBoxColumn.DisplayMember <strong class="highlight">=</strong> "Name";
            primaryComboBoxColumn.ValueMember <strong class="highlight">=</strong> "ID";

            // the <strong class="highlight">ComboBox</strong> <strong class="highlight">column</strong> is bound to the unfiltered DataView
            unfilteredSecondaryBS <strong class="highlight">=</strong> new BindingSource();
            DataView undv <strong class="highlight">=</strong> new DataView(tblSecondary);
            unfilteredSecondaryBS.DataSource <strong class="highlight">=</strong> undv;
            secondaryComboBoxColumn.DataSource <strong class="highlight">=</strong> unfilteredSecondaryBS;
            secondaryComboBoxColumn.DisplayMember <strong class="highlight">=</strong> "Name";
            secondaryComboBoxColumn.ValueMember <strong class="highlight">=</strong> "ID";

            // this binding source is where I perform my filtered view
            filteredSecondaryBS <strong class="highlight">=</strong> new BindingSource();
            DataView dv <strong class="highlight">=</strong> new DataView(tblSecondary);
            filteredSecondaryBS.DataSource <strong class="highlight">=</strong> dv;
        }
                

       
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
                if (e.ColumnIndex <strong class="highlight">=</strong>= secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb <strong class="highlight">=</strong> (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource <strong class="highlight">=</strong> filteredSecondaryBS;

                    this.filteredSecondaryBS.Filter <strong class="highlight">=</strong> "subid <strong class="highlight">=</strong> " +
                        this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
                }
            
         }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
           
                if (e.ColumnIndex <strong class="highlight">=</strong>= this.secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb <strong class="highlight">=</strong> (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource <strong class="highlight">=</strong> unfilteredSecondaryBS;

                    this.filteredSecondaryBS.RemoveFilter();
                }
        
        }

Good luck!

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.