I have found that navigation between pages in VB.NET is called like this:
Frame.Navigate(GetType(MainPage))
and from what I have read, you can pass a parameter like this:
Frame.Navigate(GetType(MainPage), "Parameter Here!!")
The problem is, I cannot get it through to the other page. Finding many examples in C# I see it might be using one of the below methods. Although, none of these seem to be recognised in VS2015
Protected Overrides Sub LoadState(navigationParameter As Object, pageState As Dictionary(Of String, Object))
Protected Overrides Sub onNavigateTo(**Params**)
^^ They both state "...does not have an override a sub in a base class"
How to I receive the parameter in the newly presented page? is it a different method entirely?
After digging into the Page class which all pages inherit from It seems overriding the "onNavigateTo" Sub is key in this operation. From here you can access its argument and pass through successfully.
Unfortunaly, even Microsoft doesn't provide VB.NET Documentation for this. Here is my code:
In the First page
Frame.Navigate(GetType(BlankPage1), "Hello")
In the Second Page
Public NotInheritable Class BlankPage1
Inherits Page
Public thestring As String
Protected Overrides Sub onNavigatedTo(e As NavigationEventArgs)
thestring = e.Parameter
End Sub
This works successfully. I hope this helps people in the future
Related
I have an app which uses about 89 different UserControls with very similar methods. I have made a base class for these UserControls with the similar methods within. Four of these methods call a function for selecting, inserting, deleting, and updating database records. My idea to handle this was to pass in these four database functions as parameters to the base class, and reference them in these base methods when I need them. Pseudo Code:
Public MustInherit Class MyAbstractBaseClass
Inherits UserControl
// Protected DatabaseInsertFunction(Of IDBRecord) As Boolean
// Protected DatabaseDeleteFunction(Of IDBRecord) As Boolean
// Protected DatabaseSelectFunction(Of IDBRecord) As Boolean
// Protected DatabaseUpdateFunction(Of IDBRecord) As Boolean
Public Sub New( InsertFunc, ...)
// Me.DatabaseInsertFun = InsertFun
...
End Sub
Protected Sub DoWork(someObject As IDBRecord)
// Do some work here
Dim result As Boolean = DatabaseInsertFunction(someObject)
...
End Sub
End Class
Public Class MyDerivedClass
Inherits MyAbstractBaseClass
Public Sub New()
MyBase.New(AddressOf InsertRecord)
End Sub
Private Sub InsertRecord(someObj as IDBRecord) As Boolean
// some work here
End Sub
End Class
I have tried every variation of syntax I can find on Google and it continues to elude me. Looking at the above code snippet, I would like to pass in the function from the derived class to the base class upon construction and store it in the base' class fields so that they can be called upon by different methods within the base class later. Using Func(Of T) is great except when there are return values I can't figure it out. Any help would be much appreciated
please see image attached.
i want it to be
Public components As System.ComponentModel.lContainer
but every time I edit the form design, it always change back to its original code
Private components As System.ComponentModel.lContainer
You can have a public Property in your class that returns a private member, like yours. This code is generated by form designer and probably you can not change the behavior of this. Even if you could, I wouldn't suggest you to do this.
Public Class MyForm
Public Property Container As System.ComponentModel.IContainer
Get
Return Me.components
End Get
End Property
End Class
Cheers
This is my first post on Stack Overflow so please exuse (and feel free to point out) any n00b mistakes.
I am trying to implement transactions across multiple TableAdapters in VB.NET (using Visual Studio 2010) by extending the partial class as described in the following examples:
http://blah.winsmarts.com/2006/06/18/the-definitive-tableadapters--transactions-blog-post.aspx
madprops.org/blog/typed-datasets-and-sqltransaction/
stackoverflow.com/questions/2342289/net-tableadapter-to-dataadapter
However, when I attempt to expose any of the private fields created by the designer they are underlined in the editor with the following error:
'_adapter' is not declared. It may be inaccessible due to its protection
level.
Searching this site as well as google has not revealed anything useful, but perhpas I'm searching the wrong keywords.
Here is the code in MyDataset.vb
Partial Public Class MyTableAdapter
Public Property MyTransaction() As SqlTransaction
Get
Return _adapter.SelectCommand.Transaction
End Get
Set(ByVal value As SqlTransaction)
If _adapter Is Nothing Then
InitAdapter()
End If
Connection = value.Connection
_adapter.InsertCommand.Transaction = value
_adapter.UpdateCommand.Transaction = value
_adapter.DeleteCommand.Transaction = value
End Set
End Property
End Class
and here is the designer code:
Partial Public Class MyTableAdapter
Inherits Global.System.ComponentModel.Component
Private WithEvents _adapter As Global.System.Data.SqlClient.SqlDataAdapter
Private _connection As Global.System.Data.SqlClient.SqlConnection
Private _transaction As Global.System.Data.SqlClient.SqlTransaction
Private _commandCollection() As Global.System.Data.SqlClient.SqlCommand
Am I missing something, or is this not possible in VB (all of the examples I've seen are in C#)?
TIA for any help!
JE
Can you access any Public properties/methods from the Adapter class?
I think you may have created your partial class in the wrong namespace. It has to be in Namespace MyDataSetTableAdapters
I am developing a VBA project in Word and have encountered a problem with handling events when using a class that implements another.
I define an empty class, IMyInterface:
Public Sub Xyz()
End Sub
Public Event SomeEvent()
And a class, MyClass that implements the above:
Implements IMyInterface
Public Event SomeEvent()
Public Sub Xyz()
' ... code ...
RaiseEvent SomeEvent
End Sub
Private Sub IMyInterface_Xyz()
Xyz
End Sub
If I create a third class, OtherClass, that declares a member variable with the type of the interface class:
Private WithEvents mMy As IMyInterface
and try to initialize this variable with an instance of the implementing class:
Set mMy = New MyClass
I get a run-time error '459': This component doesn't support this set of events.
The MSDN page for this error message states:
"You tried to use a WithEvents
variable with a component that can't
work as an event source for the
specified set of events. For example,
you may be sinking events of an
object, then create another object
that Implements the first object.
Although you might think you could
sink the events from the implemented
object, that isn't automatically the
case. Implements only implements an
interface for methods and properties."
The above pretty much sums up what I'm trying to do. The wording, "that isn't automatically the case", rather than "this is flat-out impossible", seems to suggest that there is some bit of manual work I need to do to get it to work, but it doesn't tell me what! Does anybody know if this is possible in VBA?
Apparently Events are not allowed to be passed through an interface class into the concrete class like you want to using "Implements". In this article it states: "Event declarations of the abstract interface are not included in the interface that is inherited by concrete classes. I haven't found anywhere that this has been acknowledged as a bug; however, it does seem to be one."
Here is the link to the source: http://www.devx.com/getHelpOn/10MinuteSolution/20416
:-(
i am generating a report in vb.net using itextsharp. sometimes the entire report does not fit on one page and i need to know when itextsharp is adding a page to the document. is there a way to detect this?
As long as you're implementing the PdfPageEvent interface, you just need to override the public void onEndPage(PdfWriter writer, Document document) method, which is called right before a new page is started.
Edit: here's some code explaining the procedure, without knowing what you want to do if a new page is created by iTextSharp, this is the most I can give you:
Public Class YourReport
Implements PdfPageEvent
'Your report code
Public Overrides Sub onEndPage(ByVal writer as PdfWriter,
ByVal doc as Document)
'if you get here, a new page was created by iTextSharp
'so do what you need to do.
End Sub
End Class