Binding textbox to a fixed dataset row?

G

Guest

Does anyone knwo how I can bind a textbox to a single dataset/dataTable row?

The following will give me only a Column:

textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.myDataTable, "TableNaam"))

But in my program I need a textbox (that I can edit) directly bound to a
fixed cel in a Dataset/ dataTable.

Does anyone know how I can do this ?


Bardo
 
N

Nicholas Paldino [.NET/C# MVP]

Bardo,

I don't understand exactly what you want. Basically, with the code that
you have given, you are binding a column in the table specified. If you
want a specific row, then you have to get the BindingContext for the
control, and then get the BindingManagerBase (you get it through the indexer
on the context). Once you have that, you can use it to navigate through the
rows on the dataset (the BindingManagerBase keeps track of the position).

Hope this helps.
 
G

Guest

What I need is the following. I have an access database holding different
tables. 1 table has only 1 column and has 2 rows (2 cells). This table will
not change in size. The info in these 2 cells change al lot while the using
other tables in the database. Now I need to have the content shown in 2
textboxs.

So in short.
textbox1 need to be bound to .row[0] of the table and
textbo2 need to be bound to row[1] of the table.

Bardo

Nicholas Paldino said:
Bardo,

I don't understand exactly what you want. Basically, with the code that
you have given, you are binding a column in the table specified. If you
want a specific row, then you have to get the BindingContext for the
control, and then get the BindingManagerBase (you get it through the indexer
on the context). Once you have that, you can use it to navigate through the
rows on the dataset (the BindingManagerBase keeps track of the position).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bardo said:
Does anyone knwo how I can bind a textbox to a single dataset/dataTable
row?

The following will give me only a Column:

textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.myDataTable, "TableNaam"))

But in my program I need a textbox (that I can edit) directly bound to a
fixed cel in a Dataset/ dataTable.

Does anyone know how I can do this ?


Bardo
 
N

Nicholas Paldino [.NET/C# MVP]

Bardo,

If this is the case, then you should set up different binding contexts
for each data set. You can do this by creating a new BindingContext
instance and setting it to the control's BindingContext property.

Once you do that, you can move the position of the record pointer to
whichever record in the data set you wish. The call to add the binding is
the same.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bardo said:
What I need is the following. I have an access database holding different
tables. 1 table has only 1 column and has 2 rows (2 cells). This table
will
not change in size. The info in these 2 cells change al lot while the
using
other tables in the database. Now I need to have the content shown in 2
textboxs.

So in short.
textbox1 need to be bound to .row[0] of the table and
textbo2 need to be bound to row[1] of the table.

Bardo

Nicholas Paldino said:
Bardo,

I don't understand exactly what you want. Basically, with the code
that
you have given, you are binding a column in the table specified. If you
want a specific row, then you have to get the BindingContext for the
control, and then get the BindingManagerBase (you get it through the
indexer
on the context). Once you have that, you can use it to navigate through
the
rows on the dataset (the BindingManagerBase keeps track of the position).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bardo said:
Does anyone knwo how I can bind a textbox to a single dataset/dataTable
row?

The following will give me only a Column:

textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.myDataTable, "TableNaam"))

But in my program I need a textbox (that I can edit) directly bound
to a
fixed cel in a Dataset/ dataTable.

Does anyone know how I can do this ?


Bardo
 

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