Solved

Save the text of a textbox to the database too

Posted on 2011-03-11
7
291 Views
Last Modified: 2013-12-17
Hi,

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?

Peter
private void InsertNewNode(TreeNode node)
        {
         DataRow row = null;
         DataRow ParentRow = null;
         DataTable dt = null;
         int newindex = 0;
         try
         {
             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;   <===========================

             dt.Rows.Add(row);
             TreeNode newNode = GetTreeNodeFromDataRow(row, "Description");
             node.Nodes.Add(newNode);
             tvNotes.SelectedNode = newNode; 
         }
         catch (Exception) 
		 {
			 throw;
		 }

      }

Open in new window

0
Comment
Question by:peterkiers
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
row["Data"] = textBox1.Text;
I think that is what you want
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
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?

P.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
I'm not certain what you mean.
Do you mean something like
textBox1.Text = node.Text;  //not certain if node has a Text property
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
I don't get further than this:

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

P.
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
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

P.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
Comment Utility
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?
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Thank you for the help

Peter
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now