Click here to Skip to main content
15,890,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: Getting "Input array is longer than the number of columns in this table." PinPopular
Rob Graham18-Jul-10 8:19
Rob Graham18-Jul-10 8:19 
Questionhelp: deploy c# windows application with sql server database Pin
pradeepwithu18-Jul-10 6:56
pradeepwithu18-Jul-10 6:56 
AnswerRe: help: deploy c# windows application with sql server database [modified] Pin
I Believe In GOD18-Jul-10 11:32
I Believe In GOD18-Jul-10 11:32 
Questioninheritance of atribute. Pin
prasadbuddhika18-Jul-10 1:43
prasadbuddhika18-Jul-10 1:43 
AnswerRe: inheritance of atribute. PinPopular
OriginalGriff18-Jul-10 1:50
mveOriginalGriff18-Jul-10 1:50 
GeneralRe: inheritance of atribute. Pin
Abhinav S18-Jul-10 6:42
Abhinav S18-Jul-10 6:42 
GeneralRe: inheritance of atribute. Pin
prasadbuddhika18-Jul-10 7:09
prasadbuddhika18-Jul-10 7:09 
QuestionProblem to update hierarchical data and display it in treeView. Pin
hdv21217-Jul-10 22:27
hdv21217-Jul-10 22:27 
Hi i have a simple app which display emplyees organization chart from northwind database. here is my code to accomplish this :

private void btnLoadData_Click(object sender, EventArgs e)
{
      this.treeView1.Nodes.Clear();
      
      this._dtEmployees = this.GetEmployees();
      this.FillHieraricalData(this._dtEmployees, this.treeView1, "LastName", "EmployeeID", "ReportsTo");
      this.treeView1.ExpandAll();
}

private DataTable GetEmployees()
{
      DataTable dt = new DataTable();

      using (SqlConnection con = new SqlConnection(Properties.Settings.Default.NorthwindConnectionString))
      {
        SqlCommand cmd = con.CreateCommand();
        cmd.CommandText = "select * from employees";
        con.Open();
        dt.Load(cmd.ExecuteReader());
        con.Close();
      }

      return dt;
}       

private void FillHieraricalData(DataTable dt, TreeView treeView, string infoColumnName, 
      string pkColumnName, string parentColumnName)
{
      TreeNode node = null;
      foreach (DataRow row in dt.Rows)
      {
        node = new TreeNode(row[infoColumnName].ToString());
        node.Tag = row[pkColumnName];

        if (row[parentColumnName] != DBNull.Value)
        {
          List<TreeNode> foundNodes = new List<TreeNode>();

          // search over treeView nodes to found parent of row (if exists)
          SearchNodeInTreeView(treeView.Nodes, Convert.ToInt32(row[parentColumnName]), foundNodes);
          if (foundNodes.Count > 0)
            foundNodes[0].Nodes.Add(node);
        }
        else // if row parent does not exists, then it's parent itself (or it's root), it should add to level 0 of treeView
          treeView.Nodes.Add(node);
      }
}

// this method search in treeView.Nodes to find specific nodes base on 'value'
private void SearchNodeInTreeView(TreeNodeCollection nodesToSearch, int value, List<TreeNode> foundNodes)
{
      for (int i = 0; i < nodesToSearch.Count; i++)
      {
        if (Convert.ToInt32(nodesToSearch[i].Tag) == value)
          foundNodes.Add(nodesToSearch[i]);

        //Recursively search in the child nodes        
        SearchNodeInTreeView(nodesToSearch[i].Nodes, value, foundNodes);
      }
}


However, when i update data in memory (via dataTable) and redisplay data in treeView, the row that has been modfied has been removed from treeView and not display. for example, when i change 'Reports To' of any employee, that employee does not display in treeView! here is my code to accomplish this :

private void btnSave_Click(object sender, EventArgs e)
{
      this.UpdateDataRowFromUI(this._currentRow);
      this._dtEmployees.AcceptChanges();

      this.treeView1.Nodes.Clear();
      this.FillHieraricalData(this._dtEmployees, this.treeView1, "LastName", "EmployeeID", "ReportsTo");
      this.treeView1.ExpandAll();
}

private void UpdateDataRowFromUI(DataRow row)
{
      row["LastName"] = txtLastName.Text;
      row["FirstName"] = txtFirstName.Text;
      row["ReportsTo"] = cmbReportsTo.SelectedValue;
}


Where is my problem and how to solve it ?
thanks in advance ?
AnswerRe: Problem to update hierarchical data and display it in treeView. Pin
Mycroft Holmes18-Jul-10 14:44
professionalMycroft Holmes18-Jul-10 14:44 
GeneralRe: Problem to update hierarchical data and display it in treeView. Pin
hdv21220-Jul-10 11:42
hdv21220-Jul-10 11:42 
Generalprogram c# Pin
danhco17-Jul-10 22:14
danhco17-Jul-10 22:14 
GeneralRe: program c# PinPopular
OriginalGriff17-Jul-10 22:30
mveOriginalGriff17-Jul-10 22:30 
QuestionHow can I syncronize paint events from different controls? Pin
Steven Solberg17-Jul-10 3:39
Steven Solberg17-Jul-10 3:39 
AnswerRe: How can I syncronize paint events from different controls? Pin
Luc Pattyn17-Jul-10 4:02
sitebuilderLuc Pattyn17-Jul-10 4:02 
GeneralRe: How can I syncronize paint events from different controls? Pin
Steven Solberg17-Jul-10 4:14
Steven Solberg17-Jul-10 4:14 
GeneralRe: How can I syncronize paint events from different controls? Pin
Luc Pattyn17-Jul-10 4:31
sitebuilderLuc Pattyn17-Jul-10 4:31 
GeneralRe: How can I syncronize paint events from different controls? Pin
Steven Solberg17-Jul-10 4:34
Steven Solberg17-Jul-10 4:34 
GeneralRe: How can I syncronize paint events from different controls? Pin
Luc Pattyn17-Jul-10 4:54
sitebuilderLuc Pattyn17-Jul-10 4:54 
GeneralRe: How can I syncronize paint events from different controls? [modified] Pin
Steven Solberg17-Jul-10 8:09
Steven Solberg17-Jul-10 8:09 
GeneralRe: How can I syncronize paint events from different controls? Pin
Steven Solberg22-Jul-10 22:24
Steven Solberg22-Jul-10 22:24 
QuestionManaged/Unmanaged code intraoperability: Casting between pointers Pin
Keith Vitali16-Jul-10 14:24
Keith Vitali16-Jul-10 14:24 
AnswerRe: Managed/Unmanaged code intraoperability: Casting between pointers Pin
Luc Pattyn16-Jul-10 14:43
sitebuilderLuc Pattyn16-Jul-10 14:43 
GeneralRe: Managed/Unmanaged code intraoperability: Casting between pointers Pin
Nish Nishant16-Jul-10 14:46
sitebuilderNish Nishant16-Jul-10 14:46 
GeneralRe: Managed/Unmanaged code intraoperability: Casting between pointers Pin
Luc Pattyn16-Jul-10 15:00
sitebuilderLuc Pattyn16-Jul-10 15:00 
GeneralRe: Managed/Unmanaged code intraoperability: Casting between pointers Pin
Garth J Lancaster16-Jul-10 17:44
professionalGarth J Lancaster16-Jul-10 17:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.