PC Review


Reply
Thread Tools Rate Thread

Dataset bound fields

 
 
Sol Fried
Guest
Posts: n/a
 
      4th Aug 2003
I posted this on framework.adonet but was hoping that someone in this forum
might also have an answer.

I have a TreeView which I populate with a dataset by using code like this...

foreach (DataSet1.CUSTUMERRow dr in myDataSet.CUSTOMER.Rows) {
node = treeView1.Nodes.Add(dr.NAME);
node.Tag =dr;
}

I also have several textboxes on the form that are bound to fields in
DataSet1.CUSTOMER.
I am trying to have those fields updated with the correct information
whenver a TreeView item is selected. I thought that by keeping a reference
to each dataRow in the tree node itself, I would be able to use it to
somehow move the 'Current Record' pointer so that the other Bound fields are
updated. I have tried using the CurrencyManager but cannot get that to work.

I can use the dataRow reference to manually update the fields and then
reapply the updates, but would rather use bound fields.

Any ideas would be greatly appreciated.

Thanks,
Sol


 
Reply With Quote
 
 
 
 
Jonny
Guest
Posts: n/a
 
      5th Aug 2003
hello,
you may try this way.First do some initializations in the form_load
eventhandler like this:

for(int i = 0 ; i < prodDS1.Products.Rows.Count; i++)
{
prodDS.ProductsRow dr = (prodDS.ProductsRow) prodDS1.Products.Rows[i];
TreeNode node = treeView1.Nodes.Add(dr.ProductName);
node.Tag = i;
}
Save the position of the row instead of the reference.

Then in the event_handler of treeView_afterSelect event get the treeview's
BindingContext, then the CurrencyManager and set it's Position using the
saved value in node.Tag, Like this:

TreeNode node = e.Node;
Int32 pos = (Int32) node.Tag;
BindingContext bc = treeView1.BindingContext;
CurrencyManager cm = bc[prodDS1,"Products"] as CurrencyManager;
if (cm != null)
cm.Position = pos;
else MessageBox.Show ("Invalid currency manager");

Now , it should be ok.

Regards,
Ying Shen Yu
Microsoft Partner Online Support
This posting is provided "AS IS" with no warranties, and confers no rights.



"Sol Fried" <(E-Mail Removed)> wrote in message
news:ILrXa.84692$(E-Mail Removed)...
> I posted this on framework.adonet but was hoping that someone in this

forum
> might also have an answer.
>
> I have a TreeView which I populate with a dataset by using code like

this...
>
> foreach (DataSet1.CUSTUMERRow dr in myDataSet.CUSTOMER.Rows) {
> node = treeView1.Nodes.Add(dr.NAME);
> node.Tag =dr;
> }
>
> I also have several textboxes on the form that are bound to fields in
> DataSet1.CUSTOMER.
> I am trying to have those fields updated with the correct information
> whenver a TreeView item is selected. I thought that by keeping a reference
> to each dataRow in the tree node itself, I would be able to use it to
> somehow move the 'Current Record' pointer so that the other Bound fields

are
> updated. I have tried using the CurrencyManager but cannot get that to

work.
>
> I can use the dataRow reference to manually update the fields and then
> reapply the updates, but would rather use bound fields.
>
> Any ideas would be greatly appreciated.
>
> Thanks,
> Sol
>
>




 
Reply With Quote
 
Jonny
Guest
Posts: n/a
 
      5th Aug 2003
hello,
you may try this way.First do some initializations in the form_load
eventhandler like this:

for(int i = 0 ; i < prodDS1.Products.Rows.Count; i++)
{
prodDS.ProductsRow dr = (prodDS.ProductsRow) prodDS1.Products.Rows[i];
TreeNode node = treeView1.Nodes.Add(dr.ProductName);
node.Tag = i;
}
Save the position of the row instead of the reference.

Then in the event_handler of treeView_afterSelect event get the treeview's
BindingContext, then the CurrencyManager and set it's Position using the
saved value in node.Tag, Like this:

TreeNode node = e.Node;
Int32 pos = (Int32) node.Tag;
BindingContext bc = treeView1.BindingContext;
CurrencyManager cm = bc[prodDS1,"Products"] as CurrencyManager;
if (cm != null)
cm.Position = pos;
else MessageBox.Show ("Invalid currency manager");

Now , it should be ok.

Regards,
Ying Shen Yu
Microsoft Partner Online Support
This posting is provided "AS IS" with no warranties, and confers no rights.



"Sol Fried" <(E-Mail Removed)> wrote in message
news:ILrXa.84692$(E-Mail Removed)...
> I posted this on framework.adonet but was hoping that someone in this

forum
> might also have an answer.
>
> I have a TreeView which I populate with a dataset by using code like

this...
>
> foreach (DataSet1.CUSTUMERRow dr in myDataSet.CUSTOMER.Rows) {
> node = treeView1.Nodes.Add(dr.NAME);
> node.Tag =dr;
> }
>
> I also have several textboxes on the form that are bound to fields in
> DataSet1.CUSTOMER.
> I am trying to have those fields updated with the correct information
> whenver a TreeView item is selected. I thought that by keeping a reference
> to each dataRow in the tree node itself, I would be able to use it to
> somehow move the 'Current Record' pointer so that the other Bound fields

are
> updated. I have tried using the CurrencyManager but cannot get that to

work.
>
> I can use the dataRow reference to manually update the fields and then
> reapply the updates, but would rather use bound fields.
>
> Any ideas would be greatly appreciated.
>
> Thanks,
> Sol
>
>





 
Reply With Quote
 
Jonny
Guest
Posts: n/a
 
      5th Aug 2003
hello,
you may try this way.First do some initializations in the form_load
eventhandler like this:

for(int i = 0 ; i < prodDS1.Products.Rows.Count; i++)
{
prodDS.ProductsRow dr = (prodDS.ProductsRow) prodDS1.Products.Rows[i];
TreeNode node = treeView1.Nodes.Add(dr.ProductName);
node.Tag = i;
}
Save the position of the row instead of the reference.

Then in the event_handler of treeView_afterSelect event get the treeview's
BindingContext, then the CurrencyManager and set it's Position using the
saved value in node.Tag, Like this:

TreeNode node = e.Node;
Int32 pos = (Int32) node.Tag;
BindingContext bc = treeView1.BindingContext;
CurrencyManager cm = bc[prodDS1,"Products"] as CurrencyManager;
if (cm != null)
cm.Position = pos;
else MessageBox.Show ("Invalid currency manager");

Now , it should be ok.

Regards,
Ying Shen Yu
Microsoft Partner Online Support
This posting is provided "AS IS" with no warranties, and confers no rights.



"Sol Fried" <(E-Mail Removed)> wrote in message
news:ILrXa.84692$(E-Mail Removed)...
> I posted this on framework.adonet but was hoping that someone in this

forum
> might also have an answer.
>
> I have a TreeView which I populate with a dataset by using code like

this...
>
> foreach (DataSet1.CUSTUMERRow dr in myDataSet.CUSTOMER.Rows) {
> node = treeView1.Nodes.Add(dr.NAME);
> node.Tag =dr;
> }
>
> I also have several textboxes on the form that are bound to fields in
> DataSet1.CUSTOMER.
> I am trying to have those fields updated with the correct information
> whenver a TreeView item is selected. I thought that by keeping a reference
> to each dataRow in the tree node itself, I would be able to use it to
> somehow move the 'Current Record' pointer so that the other Bound fields

are
> updated. I have tried using the CurrencyManager but cannot get that to

work.
>
> I can use the dataRow reference to manually update the fields and then
> reapply the updates, but would rather use bound fields.
>
> Any ideas would be greatly appreciated.
>
> Thanks,
> Sol
>
>






 
Reply With Quote
 
Sol Fried
Guest
Posts: n/a
 
      5th Aug 2003
Thanks,

I had tried almost exactly the same code without success.
Your code works though, the differnce being that where I
had..

CurrencyManager cm = bc[prodDS1.Products] as
CurrencyManager;

You recommended ...

CurrencyManager cm = bc[prodDS1,"Products"] as
CurrencyManager;

I thought the two should be equal. I have things working
but need to test Adds and deletes to make sure that the
dataset position values don't change for existing rows
when items are added or removed.

Thanks for the help
Sol

>-----Original Message-----
>hello,
> you may try this way.First do some initializations in

the form_load
>eventhandler like this:
>
> for(int i = 0 ; i < prodDS1.Products.Rows.Count; i++)
> {
> prodDS.ProductsRow dr = (prodDS.ProductsRow)

prodDS1.Products.Rows[i];
> TreeNode node = treeView1.Nodes.Add(dr.ProductName);
> node.Tag = i;
> }
> Save the position of the row instead of the reference.
>
> Then in the event_handler of treeView_afterSelect event

get the treeview's
>BindingContext, then the CurrencyManager and set it's

Position using the
>saved value in node.Tag, Like this:
>
> TreeNode node = e.Node;
> Int32 pos = (Int32) node.Tag;
> BindingContext bc = treeView1.BindingContext;
> CurrencyManager cm = bc[prodDS1,"Products"] as

CurrencyManager;
> if (cm != null)
> cm.Position = pos;
> else MessageBox.Show ("Invalid currency manager");
>
>Now , it should be ok.
>
>Regards,
>Ying Shen Yu
>Microsoft Partner Online Support
>This posting is provided "AS IS" with no warranties, and

confers no rights.
>
>
>
>"Sol Fried" <(E-Mail Removed)> wrote in message
>news:ILrXa.84692$(E-Mail Removed)...
>> I posted this on framework.adonet but was hoping that

someone in this
>forum
>> might also have an answer.
>>
>> I have a TreeView which I populate with a dataset by

using code like
>this...
>>
>> foreach (DataSet1.CUSTUMERRow dr in

myDataSet.CUSTOMER.Rows) {
>> node = treeView1.Nodes.Add(dr.NAME);
>> node.Tag =dr;
>> }
>>
>> I also have several textboxes on the form that are

bound to fields in
>> DataSet1.CUSTOMER.
>> I am trying to have those fields updated with the

correct information
>> whenver a TreeView item is selected. I thought that by

keeping a reference
>> to each dataRow in the tree node itself, I would be

able to use it to
>> somehow move the 'Current Record' pointer so that the

other Bound fields
>are
>> updated. I have tried using the CurrencyManager but

cannot get that to
>work.
>>
>> I can use the dataRow reference to manually update the

fields and then
>> reapply the updates, but would rather use bound fields.
>>
>> Any ideas would be greatly appreciated.
>>
>> Thanks,
>> Sol
>>
>>

>
>
>
>
>.
>

 
Reply With Quote
 
Duke Sun
Guest
Posts: n/a
 
      6th Aug 2003
The method may not work if the dataset is modified, for example, by another
thread.

You can retrieve the all other fields of the current record based on the
key field and display them, though you will have to write more codes to
implement it.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Using A Bound Dataset to insert new Cor Ligthert [MVP] Microsoft VB .NET 3 18th Jul 2006 10:42 AM
SQL Server Bit Fields & Bound Form Fields Incompatibility Micah Miller Microsoft Access ADP SQL Server 19 21st Oct 2005 01:22 AM
RE: Dataset and Bound controls Kevin Sun [MS] Microsoft ADO .NET 1 5th Aug 2003 02:59 PM
RE: dataset and bound fields Kevin Sun [MS] Microsoft ADO .NET 0 5th Aug 2003 10:35 AM
RE: Dataset bound fields Kevin Sun [MS] Microsoft ADO .NET 0 5th Aug 2003 10:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:56 AM.