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

Re: Dataset bound fields by Jonny

Jonny
Tue Aug 05 01:55:34 CDT 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" <sofried@yahoo.com> wrote in message
news:ILrXa.84692$Wd5.16696029@news4.srv.hcvlny.cv.net...
> 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
>
>




Re: Dataset bound fields by Jonny

Jonny
Tue Aug 05 01:56:14 CDT 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" <sofried@yahoo.com> wrote in message
news:ILrXa.84692$Wd5.16696029@news4.srv.hcvlny.cv.net...
> 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
>
>





Re: Dataset bound fields by Jonny

Jonny
Tue Aug 05 01:56:24 CDT 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" <sofried@yahoo.com> wrote in message
news:ILrXa.84692$Wd5.16696029@news4.srv.hcvlny.cv.net...
> 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
>
>






Re: Dataset bound fields by Sol

Sol
Tue Aug 05 09:03:26 CDT 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" <sofried@yahoo.com> wrote in message
>news:ILrXa.84692$Wd5.16696029@news4.srv.hcvlny.cv.net...
>> 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
>>
>>
>
>
>
>
>.
>

Re: Dataset bound fields by quansun

quansun
Wed Aug 06 03:20:06 CDT 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.