Binding a datagridview to a binding source

Hello,

I am using a datagridview and have bound it to a bindingsource.

In the datagridview i have a combo box column which gives the user a choice of either, ordered, pending, delivered.

However, In this specific grid I just want to display the pending orders. But if I click on the status and select delivered, I want the grid to display "delivered", Until I click save. However, what is happening then I click on the combo box and select delivered it will automatically refresh and not display delivered, only the pending orders. The customer would like to see all the orders that have had their status changed before saving and then displaying all the pending orders again.

The binding source is filtered to display only the orders pending when I select an order from the combo box.

My idea is to select an order from the combox box and display all the pending orders for that order number. The user can then select the status to delivered, if they want to. Then click save to save the changes. The save works fine. But the delivered row will disappear when the combo box loses focus.

Private Sub cboOrdersPending_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboOrdersPending.SelectionChangeCommitted
Try
Me.bsOrderDetails.Filter = String.Format("OrderID = '{0}' AND Status = '{1}'", Me.cboOrdersPending.SelectedValue, "Pending")
Me.dgvPendingOrders.DataSource = Me.bsPendingOrders

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

The code for filling the binding source is as follows:
'Fill all pending orders - these are orders that have been ordered but have not bee delivered
Private Sub FillPendingOrders()
Try
Me.TA_OrderDetails_dsCodeRed1.Fill(Me.DsAddComponetAndEquipment.OrderDetails)
Me.bsPendingOrders.Filter = String.Format("Status = '{0}'", "Pending")

Me.dgvPendingOrders.AutoGenerateColumns = False
Me.dgvPendingOrders.DataSource = Me.bsPendingOrders

'Me.HidePendingOrdersColumn()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Can someone please tell me if i have done something wrong with my code and explanation.

Many thanks for any help,

Steve
[2523 byte] By [steve1_rm] at [2007-11-20 9:07:58]
# 1 Re: Binding a datagridview to a binding source
Nothing is wrong

You have set a Filter on status = Pending

You see all pending rows

Now you edit a row so it is not Pending any more

The data model is changed

The BindSource is told the model has changed and re-filters the results to ensure the filter is obeyed

Your newly changed result is filtered out

-

Best thing I can think.. Add another column that's boolean, call it Shown

Do:

For i as Integer = 0 to myDT.Rows.Count - 1
myDT(i).Shown = myDT(i).Status.Equals("Pending") 'or whatever
Next i

BindSource.Filter = "Shown = True"

Now when you edit the rows, you arent editing a column that is a member of the filter
cjard at 2007-11-10 3:30:01 >