|
That code uses late binding to access the list in the form. You can only use late binding if you turn of strict checking, which you shouldn't.
There are basically two ways to do this:
1. Create an abstract base class that contains a property that returns a reference to the list. Make the forms inherit the base class, and implement the property.
2. Use the FindControl method to get a reference to the list.
Alternatively, make the method take a reference to the list instead of a reference to the form.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you for the reply.
I tried this code and it still doesn't work.
Public Sub ListBoxFill(ByRef aControl As System.Windows.Forms.Control)
Dim n As Integer
For n = 1 To 5
aControl.additem("Ciao")
Next
End sub
Am I doing something wrong with the reference to the list?
Aloha, Tony.
|
|
|
|
|
Sorry, let me clarify. It tells me that
AddItem is not a member of System.Windows.Forms.Control
|
|
|
|
|
Never mind, I am still thinking too much like VB6!
AddItem is a VB6 command, of course it didn't work.
Anyway, your suggestion to pass the control seems
to work. Thank you!
|
|
|
|
|
Pass the parameter as a ListBox instead of as a Control, otherwise you have to cast it before you can access the specific methods for the ListBox.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi, all.
I have one simple question, how to i open a windows form one project in other windows application project ??
I have 2 projects in one solution, and i added a refrence to my main windows application project, so i can see all the forms in other project.
Dim NewForm as windowsapp1.form1NewForm
NewForm= new windowsapp1.form1
NewForm.Show
Is there anyway to bypass this code, and open a form directly without declaring a new form and then open it?
Tnx for your help in advance.
|
|
|
|
|
C4ao5 wrote: Is there anyway to bypass this code, and open a form directly without declaring a new form and then open it?
Can you open a form without opening it ? How were you hoping to do that ? You can use Process.Start to start another exe, but that's about it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The thing is i have one main project.
In that project i want to display Windows Forms form other project.
Since i have 30 forms in that other project i dont want to declare a new form evry time i need to open it, becuse its very time consuming.
So i was just wondering is there any other way to do it ?
not to use;
Dim newForm as mainAPP.form1
newForm = New mainAPP.form1
newForm.show()
use something else to access the form directly if extists....
|
|
|
|
|
C4ao5 wrote: use something else to access the form directly if extists....
Like I said, nothing else exists, plainly the way to open a form is to create it. On what basis were you hoping for them to open, I mean, you have to do SOEMTHING, to control when it happens, right ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Right,
tnx for your help.
|
|
|
|
|
I did find a way to do it using system.reflection.
Private Sub OpenFormFromAssembly(ByVal FormName As String)
Dim MyAssembly As Reflection.Assembly = Reflection.Assembly.LoadFile(" Assembly to load ")
Dim MyTypes As Type() = MyAssembly.GetTypes
For Each mType As Type In MyTypes
If mType.BaseType Is GetType(Form) Then
If mType.Name = formName Then
Dim o As Object = Activator.CreateInstance(mType)
Dim f As Form = CType(o, Form)
f.Show()
End If
End If
Next
End Sub
No need to declare a new form evry time you need to open it.
BTW, i will load an assembly if is active in database,if user has right to access it....
Tnx for your help.
|
|
|
|
|
Sure - the real question is, why do you want to open every form modelessly ? I mean, what possible use is this ? You app has 30 different forms open, and no way of interacting with any of them. That's the core question I was asking you, why do that ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Sure - the real question is, why do you want to open every form modelessly ?
I mean, what possible use is this ?
Since im realatvly new to Vb.Net, i will ask you why not??
Main advatage is i dont need to declare a new form evry time i need to open it, instead of that i
just call a Windows Form from assambly and open it.
Im planing to have 6 projects in one solution, one project will be my main windows app in wich i will load all of my windows forms and display it to the user.(imagine the time lost if i need to
declare a new Windows Form evry time i need to open it, 6 projects > 70+ Windows Forms)
Your app has 30 different forms open, and no way of interacting with any of them.
How do you mean "no way of interacting with any of them" ??
I have now one main project(wich loks like outlook style app, and is my startup project) and in that project im adding particular form(from any of my projects) to my main panel (using controls.Add method) and displaying it to the user. So i have a good way to interact with the Windows form,
and the controls on it.
So now when you know what im planing to do, if you know/have any better solution, for the way to do it, im open for sugestions.
Tnx in advance.
Nihad.
|
|
|
|
|
C4ao5 wrote: Since im realatvly new to Vb.Net, i will ask you why not??
Because I can't imagine any real world reason to create a bunch of forms that my code cannot interact with again. Nor can I see any reason to have 30 forms on the screen at all.
C4ao5 wrote: Main advatage is i dont need to declare a new form evry time i need to open it, instead of that i
just call a Windows Form from assambly and open it.
If you want to create a form, doing it via reflection is a lot more work.
C4ao5 wrote: .(imagine the time lost if i need to
declare a new Windows Form evry time i need to open it, 6 projects > 70+ Windows Forms)
This is BS, sorry. Your app will run slower from using reflection.
C4ao5 wrote: How do you mean "no way of interacting with any of them" ??
Your 30 forms are like 30 different apps all running by themselves. None of them can cause any other form to behave differently.
C4ao5 wrote: So i have a good way to interact with the Windows form,
and the controls on it.
no. When you create a modeless form and do not store a reference to it, or even when you do, but it's a base Form, not the derived class, you have NO way of interacting with the controls on it in code, outside that form, ever again.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ok, i understand your point, so what would you sugest when developing a solution with multiple projects ??
What is the best way to do it, if any ??
I would realy like to develop an outlook style app, in wich user can select an app wich he needs
for his/hers daily work....
Rgrds.
Nihad.
|
|
|
|
|
Well, in that case, I'd develop a plugin architecture, and define an interface all plugins could expose, so that you can add functionality beyond the base Form class. I'd then have a list of those plugin types, let the user open a plugin via the sort of mechanism you're using now, but to keep those open forms in a list, so you can interact with them via that common interface, as required.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ok,
thank you for all of you help Christian.
|
|
|
|
|
Hi all!
I've Run into a problem in developing my latest VB App, how would you launch a console
window from a winform and write to and read from it using vb's ReadLine() and WriteLine()?
This is what i have so far:
Dim OutputConsole As Console
... Yep, that's it, i can't figure out how to actually show the console window, even thougn ( I think), it is actually there.
Thanks
MrWolfy
|
|
|
|
|
Hi,
I know of no way to add a visible Console to a Windows app.
AFAIK the only (easy) way to get a Console is by creating a "Console Application", which always
has a Console (which can be hidden after it has been shown initially) and which can
or can not behave as a regular Windows app, depending on your code.
|
|
|
|
|
Hi Again!
Thanks for your help, maybe i'll dress up a winform to look like a console window and
add a keylistener to run commands.
Thanks Again
MrWolfy
|
|
|
|
|
i have this two lines of code in a window service. it creates the directory but does not insert data into the database. both work in a window form project. pls i need help
Dim dailydirobj As DirectoryInfo = Directory.CreateDirectory("C:\ebube")
bllclass.InsertIncoming("filemu", "filegi", 0, "ayincha")
i have the funtion for DAL as
Public Function InsertIncoming(ByVal pfaAccount As String, ByVal myfileName As String, ByVal sent As Boolean, ByVal dNfNme As String) As Boolean
Dim params() As SqlParameter = {New SqlParameter("@pfaAccount", pfaAccount), _
New SqlParameter("@fileName", myfileName), _
New SqlParameter("@sent", sent), _
New SqlParameter("@FullPath", dNfNme)}
Try
Dim i As Integer = SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, "InsertIncoming", params)
Return (i = 1)
Catch ex As Exception
Throw ex
End Try
End Function
and the store procedure as
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertIncoming]
@pfaAccount varchar(50)
,@fileName varchar(150), @sent bit, @FullPath varchar(max)
as
INSERT INTO [diamonddb].[dbo].[Incoming]
([pfaAccount]
,[fileName], sent,FullPath)
VALUES
(@pfaAccount
,@fileName,@sent ,@FullPath)
|
|
|
|
|
Are you connected to the database? Any error messages?
|
|
|
|
|
no error message the service is running. where can i view window service run time error
i am connected to the database
|
|
|
|
|
i modify the code like this. but same problem help pls
Dim dailydirobj As DirectoryInfo = Directory.CreateDirectory("C:\ebube")
Dim ins As String = "INSERT INTO incoming([pfaAccount] ,[fileName], sent,FullPath) VALUES('ebube','fileName','0' ,'FullPath')"
Dim con As New SqlConnection("Data Source=PRGLAP11;Initial Catalog=diamonddb;Integrated Security=SSPI")
Dim com As New SqlCommand(ins, con)
con.Open()
com.ExecuteNonQuery()
con.Close()
|
|
|
|
|
I Don't like to debug Windows Services, therefore I always create seperate classes with all functionality I need and the test those on and on before calling the functions in those classes from a windows service.
|
|
|
|
|