Hi
I have two forms ( Form1, Form2).
On Form1 i have a button, when i click that button form1 must close and Form2 must Show.
How do I do that????
Thanx
Printable View
Hi
I have two forms ( Form1, Form2).
On Form1 i have a button, when i click that button form1 must close and Form2 must Show.
How do I do that????
Thanx
or this oneVB Code:
'in the form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As New Form2(Me) f.Show() End Sub 'in the form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.f.Close() End Sub 'to the constructor of the form2 Dim f As Form Public Sub New(ByVal f As Form1) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() Me.f = f 'Add any initialization after the InitializeComponent() call End Sub 'to the module...make it as a startup object Sub main() Dim f As New Form1() f.Show() Application.Run() End Sub
VB Code:
' form2 'in the main form public logged as boolean=false 'in the form load dim x as new form1() me.addownedform(x) x.showdialog() if logged = false then application.doevents() end if 'in the form1 dim m as form2 'in the formload m= me.owner 'in button click m.logged = true close() make the form2 as startup object...
courtesy of dynamic sysop :wave:
this is very simple,
VB Code:
dim x as new form2 x.show me.close
Does that work?Quote:
Originally posted by maged
this is very simple,
VB Code:
dim x as new form2 x.show me.close
Thanx
Next step is to load a Datagrid from a SQL Database
maged i dont think your code will work...
about loading the datagrid from sql
VB Code:
'cn is an sqlconnection dim dt as new datatable("sampletable") dim da as new sqldataadapter("select * from categories",cn) da.fill(dt) datagrid1.datasource = dt
Good morning to everyone, dear friends.
Dear Maged, I think your is the simplest way, but if the form in which this code is placed is the default start up object, as probably is, closing Form1, will cause your app. end.
I suggest to change:
dim x as new form2
x.show
me.close
in
Dim f2 As New Form2
Me.Hide()
f2.ShowDialog()
Me.Close()
Form1 is not really closed, until Form2 closes, but it seems so anyway.
Obviously you could really close Form1,starting from a module, running Form1, then when it will be closed, running Form2, but probably it's a good idea, at this moment, to stay on simple solutions. There will be time to worry on these subjects, for our friend chatty!:p
Anyway, it should be something like (By memory...check syntax before use. Only idea is important!!!):
Public Sub Main 'In a module and declared as starting object in project's properties
Dim F1 as new Form1
F1.ShowDialog() 'The button in F1 will close F1 itself
Dim F2 As New Form2
F2.Showdialog()
End
End Sub
Good job! :)
How do i Update, Insert or Delete a record without using a dataset.
Do i use ExecuteNonQuery?
a slight modification of mzims solution
though module can have this run but i don't recommend modules because the main purpose of module are structures and enums. the thing that needs no encapsulation. cheers mate.VB Code:
' on form1 Shared Sub Main() Dim f As New Form1() f.Show() Application.Run() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As New Form2(Me) f.Show() End Sub ' on form2 Dim f As Form Public Sub New(ByVal f As Form) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() Me.f = f 'Add any initialization after the InitializeComponent() call End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.f.Close() End Sub Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Application.Exit() End Sub
remember: application.run() has nothing on it so we should .exit() this thing. hope this helps mate. if not, sorry.
mendhak is good at this ado.net thing. i'm sure he can give exact details. but executeNonQuery() is used for non queries. sample: update, delete, entry or even create a table/database through code. one sample, a basic one cause i'm a noob too. hehehe.
where table_1 has 2 fields with data type string. cheers mate.VB Code:
dim cn as new sqlconnection() cn.connectionstring=[i]conn_string[/i] cn.open() dim cm as new sqlcommand("insert into table_name values('field1','field2')",cn) cm.executenonquery()