treybe

I have an unbound datagridview with three comboboxes (e.g. A, B, C) All three comboboxes share the same datasource and use the same valuemember. If I change the value of say combobox A, then B and C change also.

My problem is that B and C do not show the update until after I click off of combobox A. I want B and C to update as soon as I make the selection on A. How do I do this



Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

EllisKoT

Maybe i don't understand the problem but i try to help you anyway...

When you change the value of the CB A you can generate an event (on selected value changed). In this event you can try to force the value of the other 2 CB and/or you can try to set the focus (In this moment is on the CB A) on an other element, before exit the event.

I hope i help you

Ellis




Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

treybe

Here is my code associated with the datagridview, it works fine:

Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

If Me.Visible = True Then

Dim ColumnIndex

ColumnIndex = DataGridView1.CurrentCell.ColumnIndex

If ColumnIndex = 2 Then

IndexValue = DataGridView1.CurrentRow.Cells(2).Value

DataGridView1.CurrentRow.Cells(3).Value = IndexValue

DataGridView1.CurrentRow.Cells(4).Value = IndexValue

End If

If ColumnIndex = 3 Then

IndexValue = DataGridView1.CurrentRow.Cells(3).Value

DataGridView1.CurrentRow.Cells(2).Value = IndexValue

DataGridView1.CurrentRow.Cells(4).Value = IndexValue

End If

If ColumnIndex = 4 Then

IndexValue = DataGridView1.CurrentRow.Cells(4).Value

DataGridView1.CurrentRow.Cells(2).Value = IndexValue

DataGridView1.CurrentRow.Cells(3).Value = IndexValue

End If

Else

Exit Sub

End If

End Sub

How would I set focus onto another combobox on the datagridview





Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

EllisKoT

Setting focus on grid you may solve the problem:

DataGridView1.Focus()

If this doesn't works, try setting focus on an external object (external at the grid)

Ellis




Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

treybe

Ellis,

I tried your suggestion both with the datagridview.focus and textbox.focus, netiher worked. It appears that nothing happens when I make a selection (e.g. the value is changed). The update happens after I click off of the combobox. I need the update to happen as soon as the selected value in combobox A is changed.

Thanks,

Trey





Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

EllisKoT

Sorry i see that 1 thing:

Usually i develope web sites, then i don't know if this way is correct in windows application.

When i need to change object inside the grid, like comboboxes (dropdownlist in my case) i use the findcontrol for take the object in the grid and i directly change property of that object:

dim ddl as dropdownlist = CType(myitemselected.FindControl("myddl1"), DropDownList)
' where "myitemselected" is the itemrow.

ddl.selectedvalue = "value"
ddl.visible = true
....
....
Remember that i develope web sites and controls are little different. Maybe you must adapt my script to the object DataGridView.

I hope this help

Ellis




Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

Zhi-Xin Ye - MSFT

You should handle the CurrentCellDirtyStateChanged event as well, since when you're selecting in the ComboBox, the cell is still in edit mode, the changes is not committed, hence the CellValueChanged event would not fire, so you have to force the commition. Moreover, see what I do in the CellValueChanged event handler function:

Code Block

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)

{

int rIndex = this.dataGridView1.CurrentRow.Index;

object obj = this.dataGridView1.CurrentCell.Value;

this.dataGridView1[0, rIndex].Value = obj;

this.dataGridView1[1, rIndex].Value = obj;

this.dataGridView1[2, rIndex].Value = obj;

}

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{

this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

}







Re: Windows Forms Data Controls and Databinding DataGridView Combobox Refresh/Update - VB.NET 2.0

treybe

Zhi-Xin-Ye

Thank you! The CurrentCellDirtyStateChanged event did the trick.

Here is my code that now works:

Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

If Me.Visible = True Then

Dim ColumnIndex

ColumnIndex = DataGridView1.CurrentCell.ColumnIndex

If ColumnIndex = 2 Then

IndexValue = DataGridView1.CurrentRow.Cells(2).Value

DataGridView1.CurrentRow.Cells(3).Value = IndexValue

DataGridView1.CurrentRow.Cells(4).Value = IndexValue

End If

If ColumnIndex = 3 Then

IndexValue = DataGridView1.CurrentRow.Cells(3).Value

DataGridView1.CurrentRow.Cells(2).Value = IndexValue

DataGridView1.CurrentRow.Cells(4).Value = IndexValue

End If

If ColumnIndex = 4 Then

IndexValue = DataGridView1.CurrentRow.Cells(4).Value

DataGridView1.CurrentRow.Cells(2).Value = IndexValue

DataGridView1.CurrentRow.Cells(3).Value = IndexValue

End If

Else

Exit Sub

End If

End Sub

Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged

DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)

End Sub