473,888 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-FORM: Populate treeview from dataset and edit the tables in datagridview

1 New Member
Hello

I have populated a treeview from my dataset and by clicking in the treeview i want to get the corresponding table shown in a datagridview. Ive managed this by looking at each DataRow and child rows and added the nodes with a columnname from each datarow. At the same time i have put in a tag at each treenode with a filter string and the current table im looking at as a string to use for later so i can create a datatable and set a filter to that and set it as datasource to the datagridview.
So to fill my datagridview with the corresponding data from where in the treeview ive clicked, i have made an AfterSelect event. In this event i get the tag from the clicked node and use the filter string to filter which rows i would like to be shown in the datagridview. I do this because the overall table is a "Site" beneath that ive got some "Lines" and so on. So when clicking "Lines" i would like to only get the "lines" beneath the specific "Site" shown. This all works fine.
But when i create a new "Site" i can see the child tables in the treeview which is empty ofcourse. But when clicking one of the child tables like "Lines" i would like to be able to create a new "Line" in my datagridview. But when clicking the node i cant do that as theres nothing shown in the datagridview, not even column headers.
I know that this is happening because theres no datarows in the table and so i never get my filter string and datasource set.
So i would like to hear any ideas on how to get my empty tables shown in the datagridview so i can fill in new data or maybe a completly different solution to this.


Code:
Expand|Select|Wrap|Line Numbers
  1. private void CreateTree()
  2. {
  3. treeView.BeginUpdate();
  4. treeView.Nodes.Clear();
  5. TreeNode tnSiteHeader = new TreeNode("Sites");
  6. treeView.Nodes.Add(tnSiteHeader);
  7. foreach (DataRow drSite in stamdataDataSet.Tables["Site"].Rows)
  8. {
  9. TreeNode tnSite= new TreeNode(drSite["Name"].ToString());
  10. string[] tagSiteObj = new string[2];
  11. tagSiteObj[0] = "";
  12. tagSiteObj[1] = stamdataDataSet.Site.ToString();
  13. tnSiteHeader.Tag = tagSiteObj;
  14. tnSiteHeader.Nodes.Add(tnSite);
  15. TreeNode tnLineHeader = new TreeNode("Lines");
  16. tnSite.Nodes.Add(tnLineHeader);
  17.  
  18. foreach (DataRow drLine in drSite.GetChildRows("FK_ProductionEquiptment_Site"))
  19. {
  20. TreeNode tnLine = new TreeNode(drLine["Name"].ToString());
  21. string[] tagLineObj = new string[2];
  22. tagLineObj[0] = string.Format("SiteID = {0}", drLine["SiteID"].ToString());
  23. tagLineObj[1] = stamdataDataSet.Line.ToString();
  24. tnLineHeader.Tag = tagLineObj;
  25. tnLineHeader.Nodes.Add(tnLine);
  26. TreeNode tnLineControllerHeader = new TreeNode("LineControllers");
  27. tnLine.Nodes.Add(tnLineControllerHeader);
  28.  
  29. foreach (DataRow drLineController in drLine.GetChildRows("FK_LineController_Line"))
  30. {
  31. TreeNode tnLineController = new TreeNode(drLineController["DBPath"].ToString());
  32. string[] tagLineConObj = new string[2];
  33. tagLineConObj[0] = string.Format("LineID = {0}", drLineController["LineID"].ToString());
  34. tagLineConObj[1] = stamdataDataSet.LineController.ToString();
  35. tnLineControllerHeader.Tag = tagLineConObj;
  36. tnLineControllerHeader.Nodes.Add(tnLineController);
  37. }
  38. }
  39. treeView.EndUpdate();
  40. }
  41.  
  42. private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
  43. {
  44. dgvStamdata.DataSource = null;
  45. if (this.treeView.SelectedNode.Tag != null)
  46. {
  47. string[] tagObj = (string[])e.Node.Tag;
  48. string idfilter = (string)tagObj[0];
  49. string datamember = (string)tagObj[1];
  50.  
  51. DataTable dt = stamdataDataSet.Tables[datamember];
  52. dt.DefaultView.RowFilter = idfilter;
  53.  
  54. dgvStamdata.DataSource = dt;
  55. }
  56. }
  57.  
Dec 10 '07 #1
0 7180

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9418
by: Goldsworth_Systems | last post by:
I have a string containing valid XML. How do I populate a dataset based on the string, without reference to an XML schema or writing the XML to file and reading it back in again?
7
6240
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data in the same format as the XSD (the XML file/string was created using this same schema). The XML file/string may contain data for a single table or for several tables at once. The question is:
3
1227
by: Paul D. Fox | last post by:
I would like to read from Active Directory and populate a dataset to be passed in a Web Service. I can get the data from AD just fine, but can I populate a dataset with these values and do a "Return dataSetName" in my web service?
1
2496
by: Sachin | last post by:
Hi, I am working on ASP.Net 2.0 Beta 2 I am having problems creating crystal report using dataset I created a new dataset (DS_ExpCode) and a datatable (DT_ExpCode) under App_Code folder. Then i create a new crystal report A Standard Report Creation Wizard window popus up with available datasource I selected Project Data -> ADO.Net Dataset, i see the dataset recently
2
1256
by: paumierj | last post by:
Hi there Here's my question : I'd like to populate a dataset from an XML string, ie: Dim sXmlString As String sXmlString = "<root type='E-Form'><question label='This is my first question'></question><question label='This is my second question'></question></root>
5
2116
by: John | last post by:
Hi all, I'm sorry I'm reposting this but the original was urgent and I do need closure on this. I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through the dr using a dr.NextResult() but the stored proc may not return any results for one or more Select stetments. When this happens, a table is not returned so the dataset.Fill() does not populate conatin 4 tables which then each bind to a grid -...
2
24569
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should you update after closing the grid/form, etc.? Also, can you tell me the best book to buy that fully explains the DataGridView control? Thanks.
2
4176
by: Developer111 | last post by:
In vb2005, I have to load a treeview control while loading the form so make the form loading more effective therefore I use Background worker to populate treeview. I tried treeview to pass by ref and faced the error “Cross thread operation not valid: Control” accessed from a thread other than the thread it was created on..”, which makes sense. Now I want to load treeview in background and return its object then assigning it : Is this the right...
0
1582
by: Bruce Harmon | last post by:
I would like to know how to populate Treeview from a single Access table named Shipdata so that I get a treeview that looks like the attached picture. The project I am working on is in VB.net 2008 The fields I would like make into nodes are as follows: Race Base_Hull Designation Any help would be apprecated.
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.