is it save to call functions from another form?

  • Thread starter Thread starter Co
  • Start date Start date
You're right, if it's added to an invisible Form, refreshing doesn't help..
:-)




In this case I've run out of ideas. From here it's hard to say. If you don't
create another instance of Explorer1, it should work.

Another attempt: What does the code to add the node look like? Are you
performing any long running actions directly after adding the node?

Armin

Armin,

this is what happens:
from frmZoeken I call the save to Treeview option in the menu:
Case "Opslaan"
SaveQueryInTreeview()

Private Sub SaveQueryInTreeview()

Dim sNewFolder As String = "Nieuwe Map"
Dim node = Explorer1.TreeView.TopNode
Dim nodeID = node.row("ID")
node.Nodes.Add(sNewFolder)
Explorer1.AddFolder2Database(nodeID, sNewFolder)
'Explorer1.TreeView.Refresh()

End Sub

From the main form Explorer1 the node is added.
Then the folder number is added to the database:

Public Sub AddFolder2Database(ByVal iParent As Integer, ByVal
sFolderName As String)

'this code will add a new folder to the database
conn.Open()
Dim sql As String = "SELECT * FROM Kabinet"
Dim strTable As String = "Kabinet"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim newRow As DataRow

cb.QuotePrefix = "["
cb.QuoteSuffix = "]"

Try
da.FillSchema(ds, SchemaType.Source, strTable)
newRow = ds.Tables(strTable).NewRow()
newRow("foldername") = sFolderName
newRow("parent-id") = iParent

'add the new row to the dataSet
ds.Tables(strTable).Rows.Add(newRow)

'sent the updated dataSet to the database
da.Update(ds, strTable)

Catch oException As OleDbException
MessageBox.Show(oException.Message)

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
conn.Close()
'now let's update the treeview with the new node.
TreeView.Nodes.Clear()
Call LoadTree()

End Sub

So everything here is done except that the newly added node isn't
shown.

Marco
 
You're right, if it's added to an invisible Form, refreshing doesn't help..
:-)




In this case I've run out of ideas. From here it's hard to say. If you don't
create another instance of Explorer1, it should work.

Another attempt: What does the code to add the node look like? Are you
performing any long running actions directly after adding the node?

Armin

I think I might have found it:

When I reload the treeview the new nodes aren't add.

Public Sub LoadTree()
' TODO: Add code to add items to the treeview

Dim sql As String = "SELECT * FROM Kabinet"
Dim cmd As New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader
conn.Open()
dr = cmd.ExecuteReader()

'if this is a rebuild then we don't have to add new columns to
the datatable
If dt.Columns.Count = 0 Then
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("IDParent", GetType(Integer))
End If

If dt.Rows.Count = 0 Then
While dr.Read()
dt.Rows.Add(dr.Item("Id"), dr.Item("foldername"),
dr.Item("parent-Id"))
End While
End If
AddNodes(TreeView.Nodes, dt.Select("ISNULL(IDParent, -1) =
-1"))

dr.Close()
conn.Close()

End Sub

The next line I think is killing me:

'if this is a rebuild then we don't have to add new columns to the
datatable

Am I right?

Marco
 
You're right, if it's added to an invisible Form, refreshing doesn't help..
:-)




In this case I've run out of ideas. From here it's hard to say. If you don't
create another instance of Explorer1, it should work.

Another attempt: What does the code to add the node look like? Are you
performing any long running actions directly after adding the node?

Armin

I think I might have found it:

When I reload the treeview the new nodes aren't add.

Public Sub LoadTree()
' TODO: Add code to add items to the treeview

Dim sql As String = "SELECT * FROM Kabinet"
Dim cmd As New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader
conn.Open()
dr = cmd.ExecuteReader()

'if this is a rebuild then we don't have to add new columns to
the datatable
If dt.Columns.Count = 0 Then
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("IDParent", GetType(Integer))
End If

If dt.Rows.Count = 0 Then
While dr.Read()
dt.Rows.Add(dr.Item("Id"), dr.Item("foldername"),
dr.Item("parent-Id"))
End While
End If
AddNodes(TreeView.Nodes, dt.Select("ISNULL(IDParent, -1) =
-1"))

dr.Close()
conn.Close()

End Sub

The next line I think is killing me:

'if this is a rebuild then we don't have to add new columns to the
datatable

Am I right?

Marco
 
Back
Top