Jump to content
Xtreme .Net Talk

rgreen

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by rgreen

  1. I need some help using datasets and treeviews. I'm working a small private project that fills a treeview from a database. This works OK using the FillTree() sub below. When a treeview node is clicked I want to be able to fill other controls on my form with data from the same database. I cannot work out how to do this. Can someone please help me complete tvCodeExplore_AfterSelect() Any help would be invaluable Many thanks Russ #Region " Treeview Code " Private Sub FillTree() Dim rootAdapter As New OleDbDataAdapter("SELECT * FROM tblSource WHERE ParentID = 0", conn) Dim childAdapter As New OleDbDataAdapter("SELECT * FROM tblSource WHERE ParentID <> 0", conn) Dim treeDataSet As New DataSet() treeDataSet.EnforceConstraints = False rootAdapter.Fill(treeDataSet, "Parents") childAdapter.Fill(treeDataSet, "Children") treeDataSet.Relations.Add("DBtoFolder", treeDataSet.Tables("Parents").Columns("ID"), treeDataSet.Tables("Children").Columns("ParentID")) treeDataSet.Relations.Add("FolderToItem", treeDataSet.Tables("Children").Columns("ID"), treeDataSet.Tables("Children").Columns("ParentID")) tvCodeExplore.Nodes.Clear() Dim parent As DataRow For Each parent In treeDataSet.Tables("Parents").Rows Dim parentNode As New TreeNode(parent("Name").ToString()) DIm child As DataRow For Each child In parent.GetChildRows("DBtoFolder") Dim folderNode As New TreeNode(child("Name").ToString()) Dim item As DataRow For Each item In child.GetChildRows("FolderToItem") folderNode.Nodes.Add(New TreeNode(item("Name").ToString())) Next item parentNode.Nodes.Add(folderNode) Next child tvCodeExplore.Nodes.Add(parentNode) Next parent tvCodeExplore.Nodes(0).Expand() End Sub Private Sub tvCodeExplore_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvCodeExplore.AfterSelect 'If the e.Node.Parent doesnt exist in otherwords... If e.Node.Parent Is Nothing Then Me.lblTitle.Text = e.Node.Text Me.rtbNotes.Rtf = Nothing Me.ctbVB.Text = Nothing Me.ctbCSharp.Text = Nothing Me.ctbCPlus.Text = Nothing Me.ctbJava.Text = Nothing Me.ctbHTML.Text = Nothing Me.TabPage7.Title = Nothing 'if it Does exist... ElseIf Not e.Node.Parent Is Nothing Then Me.lblTitle.Text = e.Node.Text Me.rtbNotes.Rtf = 'notes column from database to go in here Me.ctbVB.Text = 'CodeVB column from database to go in here Me.ctbCSharp.Text = 'CodeCS column from database to go in here Me.ctbCPlus.Text = 'CodeCPP column from database to go in here Me.ctbJava.Text = 'CodeJava column from database to go in here Me.ctbHTML.Text = 'CodeHTML column from database to go in here Me.TabPage7.Title = 'CodeOtherName column from database to go in here End If End Sub #End Region
  2. I have been working on an extended version of LiveUpdater that includes the ability to create local folders, delete local files and execute a downloaded file. Its also uses xml rather than ini and dat. It's early days but you can get it here Download project here Its a little buggy, but I'm working on it.
  3. I'm having a real hard time trying to get this funtion to work correctly Public Function PopulateListContol(ByVal ListControl As Object, ByVal ValMem As String, _ ByVal DisMem As String, ByVal Database As String, ByVal DataTable As String, ByRef ds As DataSet) Try 'connection stuff Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM " & DataTable, _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database) da.Fill(ds) ListControl.DataSource = ds.Tables(0) ListControl.DisplayMember = DisMem ListControl.ValueMember = ValMem Catch ex As Exception MsgBox(ex.Message) End Try End Function I'm calling the function during a form load event in a block of code like this: 'declare the datasets Dim dsClientCorp As New DataSet() 'etc.... 'fill combo boxes PopulateListContol(Me.cboClientCorp, "ClientCorpID", "CompanyName", PathtoDB & ProjectDB, "ClientCorp", dsClientCorp) 'etc... So far so good, everything seems to work. All the combos populate with the CompanyName field from the correct tables. When I try to write to another table, the ValueMember isn't writing out correctly. The wrong number is being inserted everytime. I have an access database that consists of 10 tables (Projects, ClientPvt, ClientCorp, Architect, Contractor, LandArch, ProjMan, QuantSurv, ServEng, StrucEng) All are address books except the Projects table which stores information related to jobs (this is a tool for managing job data in an Architectural practice). �Setup new project� form has various text boxes and a range of combos. Some of the combos are populated with the tables in the database. The only two fields required from each of the address-book tables are the "CompanyName" and "ID" fields. I want to display the CompanyName in each Combo but to to save the value in the ID field to the Projects table. Easy right? In the case of the Architect table I have a combo called cboArchitect. cboArchitect is being populated with ArchitectID and CompanyName fields from the Architect table. CompanyName is being displayed in the combo and ArchitectID is being assigned as ValueMember (I hope). ArchitectID is the primary key in the table. When the new project form is complete and saved the ValueMember (ArchitectID) is written to the Projects table into a field called ArchitectID (a number field - Long Integer). The save code: Dim daProjects As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & PathtoDB & ProjectDB Dim strSQL As String Try ' Define a query string strSQL = "INSERT INTO Projects ([Number], [Name], <<MORE FIELDS IN HERE>>, [ArchitectID]) VALUES ('" strSQL = strSQL & Me.txtJobNumber.Text & "', '" & Me.txtJobName.Text & "', <<MORE VALUES IN HERE>>,'" & Me.cboArchitect.SelectedValue & "')" 'Connection Stuff Dim ocon As OleDbConnection = New OleDbConnection(daProjects) ocon.Open() 'Command Object to Execute the SQL Dim ocmd As OleDbCommand = New OleDbCommand(strSQL, ocon) ocmd.ExecuteNonQuery() 'Cleanup ocmd = Nothing ocon.Close() Catch ex As Exception MsgBox(ex.Message) End Try PathtoDB & ProjectDB combine to form the full path and filename of the database. Please help, I'm totally confused on this one. Many thanks Russ
×
×
  • Create New...