Solved

Save the text of a textbox to the database too

Posted on 2011-03-11
7
293 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make all values in arrayist to titlecase+vb.net 23 27
Definitions and default visual studio colors 5 58
What is Thread.Sleep? 5 44
how to read json value 2 27
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.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

947 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

21 Experts available now in Live!

Get 1:1 Help Now