Save the text of a textbox to the database too


I have a treeview on the left and a textbox on the right devided with a splitter.
The treeview is saved to a database. Now I want the content of the textbox
saved to the database too.

I have this code in the code section.
What is the right way to save the content of the textbox
in to the database. I have tried to write the onle line
myself but it doesn't do what I want. I have marked the
line with an arrow. What should this be to save the content
of the textbox to a database?

private void InsertNewNode(TreeNode node)
         DataRow row = null;
         DataRow ParentRow = null;
         DataTable dt = null;
         int newindex = 0;
             ParentRow = (DataRow)node.Tag; 
             if (ParentRow == null) { return; }
             newindex = int.Parse(ParentRow["SortOrder"].ToString()) + 1;
             dt = ParentRow.Table;
             row = dt.NewRow();
             row["ModelID"] = int.Parse(ParentRow["ModelID"].ToString());
			 row["NodeID"] = Guid.NewGuid().ToString();
			 row["ParentNodeID"] = ParentRow[dt.PrimaryKey[0].ColumnName].ToString();
             row["Description"] = "New Node";
			 row["ImageIndex"] = 1;
			 row["SelectedImageIndex"] = 2;
             row["SortOrder"] = newindex;
             row["Data"] = textBox1;   <===========================

             TreeNode newNode = GetTreeNodeFromDataRow(row, "Description");
             tvNotes.SelectedNode = newNode; 
         catch (Exception) 


Open in new window

Who is Participating?
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
TreeViewEventArgs has a node property - the node of the treeview being selected.  Have a look at what properties that exposes to find out what you need to be displayed.

textBox1.Text = e.Node.Text;  // Is this what you want?
AndyAinscowFreelance programmer / ConsultantCommented:
row["Data"] = textBox1.Text;
I think that is what you want
peterkiersAuthor Commented:
Oke, and I know its another question but perhaps you know the answer to that too.

I have to use the treeview.afterselect event
When i click on a node the text in the textbox that is associated with that node
have to be displayed.

Do you have any idea how to?

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

AndyAinscowFreelance programmer / ConsultantCommented:
I'm not certain what you mean.
Do you mean something like
textBox1.Text = node.Text;  //not certain if node has a Text property
peterkiersAuthor Commented:
I don't get further than this:

private void tvNotes_AfterSelect(object sender, TreeViewEventArgs e)
       textBox1.Text = ?????????

peterkiersAuthor Commented:
What I meant is:

When a node is selected in the treeview
then de text of column Data of the row
has to be displayed in the textbox

peterkiersAuthor Commented:
Thank you for the help

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.