DataBinding to a DataRow?

  • Thread starter Software Department
  • Start date
S

Software Department

Greetings,

Is it possible to DataBind to a DataRow using a control such as a TextBox?
If so, what would be the correct syntax? A typed DataSet provides the means
to perform DataBinding with a DataRow, but what about an untyped DataSet?

Thanks,
 
C

Cor Ligthert

Hi Eric,
Is it possible to DataBind to a DataRow using a control such as a TextBox?
If so, what would be the correct syntax? A typed DataSet provides the means
to perform DataBinding with a DataRow, but what about an untyped DataSet?

Even easier
textbox1.DataBindings.Add(New Binding("Text", ds.Tables(0), "MyField"))
cma = DirectCast(BindingContext(ds.Tables(0)), CurrencyManager)

(the second is for your next question it has to be declared as Private cma
as CurrencyManager)

I hope this helps?

Cor
 
S

Software Department

Cor,

This example binds the column from a DataTable to a TextBox, not a DataRow
(subtle difference). I was considering using the NewRow() method of the
DataTable to get a DataRow to bind to controls on a Windows Form (displays
only one row at a time, no grids). I could use the DataRow to display an
existing record for edit or a new row. I am not opposed to binding through
the DataSet/DataTable. I am looking for input on technique... especially
since a typed DataSet provides rich properties to bind to (column names from
the table).

Thanks
 
C

Cor Ligthert

Hi,

Yes that goes perfectly fine when you use the method I did give above and
add a row to the datatable. Everything what goes with a typed dataset goes
as well with a untyped dataset, which is the base of the typed dataset.

The new row is (when added, and therefore binded in my sample)
dataset.tables(0).rows(dataset.tables(0).rows.count-1)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top