Solved

Save the text of a textbox to the database too

Posted on 2011-03-11
7
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

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

Author Comment

by:peterkiers
ID: 35112148
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
ID: 35112232
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 1

Author Comment

by:peterkiers
ID: 35112257
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
ID: 35112272
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
ID: 35112287
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
ID: 35112460
Thank you for the help

Peter
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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