binding question - add/edit with 2 forms

  • Thread starter Thread starter matt tagliaferri
  • Start date Start date
M

matt tagliaferri

Can someone tell me how to accomplish the following:

Form 1 contains a grid (Janus) bound to a DataTable within a Dataset.
I don't like editing in the grid, so I have Add/Edit/Del buttons next
to the grid.

When the user clicks "Add", I want to "send" the DataTable to another
Form (constructor? property?) where a new row can be added to the
datatable, bound to textboxes, etc on the form, for editing. If the
user hits CANCEL on form2, though, I need to make sure the Add doesn't
happen.

If the user clicks "Edit", the same editing form would be called up,
only on the current row. Same binding would happen on the edit form,
and again, if the user hits cancel, no changes occur.

What do I need to send to Form2 to allow the binding to happen? How do
I "cancel" the editing, esp. in the "Add" case?

thanks,
matt tag
 
better do this by using form constructor .pass the
datatable

u can cancel in case of "add" by using table.rejectchanges

u can cancel in case of edit by using me.bindingonctext
(table,col).cancelcurrentedit
 
What you want to do is easier to accomplish with a single
Form. Add a DataGrid to a part of the Form (top or
bottom), and place your textboxes in the remaining
space. Then in the code that loads the datatable (or
dataset), add code similar to the following.

dim dv as dataview = MyDataTable.DefaultView
(If using DataSet, use MyDataSet.Tables
("MyDataTable").DefaultView)

DataGrid1.ReadOnly = True
DataGrid1.SetDataBinding(dv, "")
TextBoxLastname.DataBindings.Add("Text", dv, "lastname")
TextBoxFirstname.DataBindings.Add("Text", dv, "firstname")
TextBoxAddress.DataBindings.Add("Text", dv, "address")
etc.

Now when the user selects a row in the DataGrid, the
textboxes will change to the same row, where the user can
edit the information.

Javed
 
Back
Top