|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
BindingManagerBase ProblemI have several textboxes bound to a DataGrid1 and a couple of buttons including 'btnNewRecord'. The datagrid is bound to a table in a dataset. What happen is that btnNewRecord adds a new row to DataGrid1 as expected, however the active row does not move to the newly added row! What am I missing? Here is pertainent code... ===== Code 1 === Public Class frmJobCustomer Inherits frmForm1 [" Window Form Designer generated code "] Private _bmb As BindingManagerBase Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewRecord.Click _bmb.AddNew() End Sub Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged Dim _currentRow As Integer = DataGrid1.CurrentCell.RowNumber Me.DataGrid1.Select(_currentRow) _bmb.Position = _currentRow End Sub Private Sub btnCancelChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelChanges.Click _bmb.CancelCurrentEdit() End Sub Private Sub btnSaveChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveChanges.Click _bmb.EndCurrentEdit() End Sub Private Sub JobCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Get ds from the DAL Dim JobCustomerDB As New DALCL.Tables localDsTables1 = JobCustomerDB.GetDaJobCustomer Me.DataGrid1.DataSource = localDsTables1.tblJobCustomer Call CreateBindings() End Sub Private Sub CreateBindings() ' Add control configuratioins to the collection Me.lblpkJobCustomerId.DataBindings.Add("Text", Me.localDsTables1.tblJobCustomer, "pkJobCustomerId") Me.txtJobNumber.DataBindings.Add("Text", Me.localDsTables1.tblJobCustomer, "JobNumber") Me.txtJobDescription.DataBindings.Add("Text", Me.localDsTables1.tblJobCustomer, "JobDescription") Me.txtShopPSI.DataBindings.Add("Text", Me.localDsTables1.tblJobCustomer, "ShopPsi") Me.chkApproved.DataBindings.Add("Checked", Me.localDsTables1.tblJobCustomer, "Approved") _bmb = Me.BindingContext(Me.localDsTables1.tblJobCustomer) _bmb.Position = 0 End Sub End Class === End Code 1 === I have also tried this code for the btnNewRecord with no success. === Code 2 === Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewRecord.Click 'Add a row and go to it Me.BindingContext(Me.DataSet1.Customers).AddNew() Me.BindingContext(Me.DataSet1.Customers).Position = _ Me.DataSet1.Customers.Rows.Count - 1 End Sub === End Code 2 ==== I want to be able to edit the new row with my bound textboxes. What can I do to correct the behavior and have the selected datagrid row become the newly created row? - Doug Doug,
When you show something, than delete all duplicates and try to not to use all kind of synonimes of tables. At first sight I will see looking at what you are showing that you are binding apples and pears. However I made a little simple sample for you. Try that. \\\needs a datagrid and two buttons on a form Dim cma As CurrencyManager Dim dv As DataView Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As New DataTable Button1.Text = "New" Button2.Text = "Accept" dt.Columns.Add("Name") dt.LoadDataRow(New Object() {"Dough"}, True) dt.LoadDataRow(New Object() {"Peter"}, True) dt.LoadDataRow(New Object() {"Cor"}, True) dv = dt.DefaultView DataGrid1.DataSource = dv dv.AllowNew = False dv.AllowEdit = False cma = DirectCast(BindingContext(dv), CurrencyManager) TextBox1.DataBindings.Add("Text", dv, "Name") End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click dv.AllowNew = True cma.AddNew() dv.AllowNew = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click cma.EndCurrentEdit() End Sub /// I hope this helps a little bit? Cor
Help with Debugging
Paging by example - help - still no luck.... Get processes list problem (win 2000) Hide members in a derived class Reading an XML file into a Dataset - problem Response.Redirect("WebForm1.aspx") Sharing references/members Custom Collections : overriding toString VB.net Ablauf vom packen eines Projekts Web Application using VB.NET |
|||||||||||||||||||||||