Dataset.Rows.Find and CurrencyManager

  • Thread starter Thread starter Sol Fried
  • Start date Start date
S

Sol Fried

Here's the problem,

I am populating a TreeView with the contents of a (Strongly typed) dataset.

for (int i = 0; i < dataSet.Cust.Rows.Count; i++) {
DataSet.CustRow row = (DataSet.CustRow)dataSet.Cust.Rows;
TreeNode node = treeView1.Nodes.Add(row.CUST_NAME);

node.Tag = row.CUST_ID;
}

I also have several field controls on the Form which are dataBound to the
dataset fields.

In the tree node AfterSelect event, I am trying to move the
CurrencyManager.Postion value so that the Bound fields are updated with the
values in the corresponding rows. (It would have been nice to have a
databound treeview control)
I retrieve the node.Tag and do a Find on the dataset row. This does not
move the Postion in the Currency Manager.
I tried saving the Position in the node.Tag. That worked until I started
inserting new nodes into the Dataset and could not find the Position in the
Currency Manager refering to the inserted dataset row.

I also tried using CurrencyManager.AddNew(). The Position does not seem to
change on that command and I am not clear as to how a new dataRow is added
and populated as a result of AddNew.

Any ideas how to implement this?

Thanks
Sol
 
FYI,

I was reading David Sceppa's Core reference and came upon the DataView
section.
Interestingly, the DataView.Find() returns a rowId as opposed to a Row
reference returned from a datasetRow.Find.

Using this I created a dataview that filters nothing and sorts on my tables
primary key. This was done entirely from the designer.

In the AfterSelect on the treeView, I obtain the table key value (stored in
the Node.Tag) and do a Find on the DataView.
I then use the returned index to set the CurrencyManager.Position.

The View is always in synch with the underlying table, so I can
add/modify/delete the table and the View is always up-to-date.

Sol

Stephen Muecke said:
Sol,

"....It would have been nice to have a databound treeview control.."
The following link discusses creating an inherited TreeView which supports
DataBinding

http://msdn.microsoft.com/library/en-us/dnwinforms/html/custcntrlsamp3.asp

Stephen


Sol Fried said:
Here's the problem,

I am populating a TreeView with the contents of a (Strongly typed) dataset.

for (int i = 0; i < dataSet.Cust.Rows.Count; i++) {
DataSet.CustRow row = (DataSet.CustRow)dataSet.Cust.Rows;
TreeNode node = treeView1.Nodes.Add(row.CUST_NAME);

node.Tag = row.CUST_ID;
}

I also have several field controls on the Form which are dataBound to the
dataset fields.

In the tree node AfterSelect event, I am trying to move the
CurrencyManager.Postion value so that the Bound fields are updated with the
values in the corresponding rows. (It would have been nice to have a
databound treeview control)
I retrieve the node.Tag and do a Find on the dataset row. This does not
move the Postion in the Currency Manager.
I tried saving the Position in the node.Tag. That worked until I started
inserting new nodes into the Dataset and could not find the Position in the
Currency Manager refering to the inserted dataset row.

I also tried using CurrencyManager.AddNew(). The Position does not seem to
change on that command and I am not clear as to how a new dataRow is added
and populated as a result of AddNew.

Any ideas how to implement this?

Thanks
Sol

 
Back
Top