MsgBox not displayed on 1st click after changing content in textbox - vb.net

I am trying to learn by creating this basic form. where the user is asked a password and username
currently both are text field and insecure.
the problem is that whenever i change any of the 2 fields the 1st click does not work.
the code works fine from 2nd click.
edit- there is no problem till the user and password are wrong.
here is the snippet
Private Sub BtnLogIn_Click(sender As Object, e As EventArgs) Handles BtnLogIn.Click
If (TxtUsername.Text = "shikhar" And TxtPassword.Text = "pass") Then
'goto next screen & remove message box'
MsgBox("correct Username or Password", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "login Completed")
Else
MsgBox("Incorrect Username or Password", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "login error")
End If
End Sub
this is the overall file-
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Login
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.lblUsername = New System.Windows.Forms.Label()
Me.lblPassword = New System.Windows.Forms.Label()
Me.TxtUsername = New System.Windows.Forms.TextBox()
Me.TxtPassword = New System.Windows.Forms.TextBox()
Me.BtnLogIn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'lblUsername
'
Me.lblUsername.AutoSize = True
Me.lblUsername.Location = New System.Drawing.Point(69, 84)
Me.lblUsername.Name = "lblUsername"
Me.lblUsername.Size = New System.Drawing.Size(55, 13)
Me.lblUsername.TabIndex = 0
Me.lblUsername.Text = "Username"
'
'lblPassword
'
Me.lblPassword.AutoSize = True
Me.lblPassword.Location = New System.Drawing.Point(69, 130)
Me.lblPassword.Name = "lblPassword"
Me.lblPassword.Size = New System.Drawing.Size(53, 13)
Me.lblPassword.TabIndex = 1
Me.lblPassword.Text = "Password"
'
'TxtUsername
'
Me.TxtUsername.Location = New System.Drawing.Point(178, 77)
Me.TxtUsername.Name = "TxtUsername"
Me.TxtUsername.Size = New System.Drawing.Size(199, 20)
Me.TxtUsername.TabIndex = 2
'
'TxtPassword
'
Me.TxtPassword.Location = New System.Drawing.Point(178, 123)
Me.TxtPassword.Name = "TxtPassword"
Me.TxtPassword.Size = New System.Drawing.Size(198, 20)
Me.TxtPassword.TabIndex = 3
'
'BtnLogIn
'
Me.BtnLogIn.Location = New System.Drawing.Point(181, 172)
Me.BtnLogIn.Name = "BtnLogIn"
Me.BtnLogIn.Size = New System.Drawing.Size(164, 45)
Me.BtnLogIn.TabIndex = 4
Me.BtnLogIn.Text = "Log In"
Me.BtnLogIn.UseVisualStyleBackColor = True
'
'Login
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(474, 261)
Me.Controls.Add(Me.BtnLogIn)
Me.Controls.Add(Me.TxtPassword)
Me.Controls.Add(Me.TxtUsername)
Me.Controls.Add(Me.lblPassword)
Me.Controls.Add(Me.lblUsername)
Me.Name = "Login"
Me.Text = "Login"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents lblUsername As System.Windows.Forms.Label
Friend WithEvents lblPassword As System.Windows.Forms.Label
Friend WithEvents TxtUsername As System.Windows.Forms.TextBox
Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
Friend WithEvents BtnLogIn As System.Windows.Forms.Button
End Class

Related

Form childs doesn't resize when form resize because of minimumsize

I have a form with a SplitContainer in dock fill. In panel 1 of the split container I have buttons, in panel 2, I have a UserControl in dock fill. The Usercontrol classes in panel2 change depending on buttons clicked in panel1 but is kept dock fill.
Each Usercontrol have a minimum size.
The MinimumSize of the form is recalculate every time I change UCs and also when I move the splitter. This looks perfectly fine.
When I resize the form manually, everything follow as intended by default : fine. Meaning, the form can't be resized under minimum size value.
When I move the splitter manually, everything follow as intended by default : fine. Meaning, panel 1 and panel 2 UC resize as well as all the children.
But, when at any given moment if the form is at minimum size and I try to move the slider. The form resize properly to allow panel 2 UC minimum size to fit BUT the UC doesn't resize...
Any idea why and how to fix it?
As suggested, I simplified the application to a minimum and here is the code of the MainForm :
Public Class MainForm
Private Sub SetMinSize()
Dim borderWidth = Me.Width - Me.ClientSize.Width
Me.MinimumSize = New Size(borderWidth + Me.SplitContainerMain.Panel1.Size.Width + Me.SplitContainerMain.SplitterWidth + Me.MainUserControl.MinimumSize.Width,
Me.MinimumSize.Height)
End Sub
Private Sub MainUserControl_ControlAdded(sender As Object, e As ControlEventArgs)
Me.SetMinSize()
End Sub
Private Sub SplitContainerMain_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles SplitContainerMain.SplitterMoved
Me.SetMinSize()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.SuspendLayout()
Me.SplitContainerMain.Panel2.Controls.Remove(Me.MainUserControl)
Try ' The try catch avoid error in case the handle is not created
RemoveHandler Me.MainUserControl.ControlAdded, AddressOf Me.MainUserControl_ControlAdded
Catch ex As Exception
End Try
Me.MainUserControl.Dispose()
Me.MainUserControl = New UC1UserControl
Me.MainUserControl.Dock = DockStyle.Fill
Me.SplitContainerMain.Panel2.Controls.Add(Me.MainUserControl)
AddHandler Me.MainUserControl.ControlAdded, AddressOf Me.MainUserControl_ControlAdded
Me.ResumeLayout()
Me.SetMinSize()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.SuspendLayout()
Me.SplitContainerMain.Panel2.Controls.Remove(Me.MainUserControl)
Try ' The try catch avoid error in case the handle is not created
RemoveHandler Me.MainUserControl.ControlAdded, AddressOf Me.MainUserControl_ControlAdded
Catch ex As Exception
End Try
Me.MainUserControl.Dispose()
Me.MainUserControl = New UC2UserControl
Me.MainUserControl.Dock = DockStyle.Fill
Me.SplitContainerMain.Panel2.Controls.Add(Me.MainUserControl)
AddHandler Me.MainUserControl.ControlAdded, AddressOf Me.MainUserControl_ControlAdded
Me.ResumeLayout()
Me.SetMinSize()
End Sub
End Class
And this is the designer:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class MainForm
Inherits System.Windows.Forms.Form
'Form remplace la méthode Dispose pour nettoyer la liste des composants.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Requise par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée à l'aide du Concepteur Windows Form.
'Ne la modifiez pas à l'aide de l'éditeur de code.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.SplitContainerMain = New System.Windows.Forms.SplitContainer()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.MainUserControl = New UserControl()
CType(Me.SplitContainerMain, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SplitContainerMain.Panel1.SuspendLayout()
Me.SplitContainerMain.Panel2.SuspendLayout()
Me.SplitContainerMain.SuspendLayout()
Me.SuspendLayout()
'
'SplitContainerMain
'
Me.SplitContainerMain.Dock = System.Windows.Forms.DockStyle.Fill
Me.SplitContainerMain.FixedPanel = System.Windows.Forms.FixedPanel.Panel1
Me.SplitContainerMain.Location = New System.Drawing.Point(0, 0)
Me.SplitContainerMain.Name = "SplitContainerMain"
'
'SplitContainerMain.Panel1
'
Me.SplitContainerMain.Panel1.Controls.Add(Me.Button2)
Me.SplitContainerMain.Panel1.Controls.Add(Me.Button1)
Me.SplitContainerMain.Panel1MinSize = 170
'
'SplitContainerMain.Panel2
'
Me.SplitContainerMain.Panel2.Controls.Add(Me.MainUserControl)
Me.SplitContainerMain.Panel2MinSize = 0
Me.SplitContainerMain.Size = New System.Drawing.Size(784, 561)
Me.SplitContainerMain.SplitterDistance = 170
Me.SplitContainerMain.TabIndex = 0
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(40, 110)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
Me.Button2.UseVisualStyleBackColor = True
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(40, 41)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'MainUserControl
'
Me.MainUserControl.Dock = System.Windows.Forms.DockStyle.Fill
Me.MainUserControl.Location = New System.Drawing.Point(0, 0)
Me.MainUserControl.Name = "MainUserControl"
Me.MainUserControl.Size = New System.Drawing.Size(610, 561)
Me.MainUserControl.TabIndex = 0
'
'MainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoSize = True
Me.ClientSize = New System.Drawing.Size(784, 561)
Me.Controls.Add(Me.SplitContainerMain)
Me.MinimumSize = New System.Drawing.Size(800, 600)
Me.Name = "MainForm"
Me.Tag = ""
Me.Text = "Demo"
Me.SplitContainerMain.Panel1.ResumeLayout(False)
Me.SplitContainerMain.Panel2.ResumeLayout(False)
CType(Me.SplitContainerMain, System.ComponentModel.ISupportInitialize).EndInit()
Me.SplitContainerMain.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents SplitContainerMain As SplitContainer
Friend WithEvents MainUserControl As UserControl
Friend WithEvents Button2 As Button
Friend WithEvents Button1 As Button
End Class
And Here is some screen shots :
UC1UserControl displayed correctly
UC2UserControl displayed correctly
UC2UserControl after spliter moved
There is finally no code in UC1UserControl and UC2UserControl except an Label and and a different backcolor to identifiy the UC.
Thanks
After several hours of testing, logging ,etc...
I have found a solution to this.
I have added a line in the sub SetMinSize :
Private Sub SetMinSize()
Dim borderWidth = Me.Width - Me.ClientSize.Width
Me.MinimumSize = New Size(borderWidth + Me.SplitContainerMain.Panel1.Size.Width + Me.SplitContainerMain.SplitterWidth + Me.MainUserControl.MinimumSize.Width,
borderHeight + Me.MainUserControl.MinimumSize.Height)
Me.SplitContainerMain.Panel2.Size = Me.MainUserControl.Size
End Sub
And now it works. Apparently, when moving the splitter, the right panel of the SplitContainer (SplitContainerMain.Panel2) wasn't resized after the form resized.

I've trying to make a simple application in visual basic.NET,

I'm new to Visual Basic.NET and I've been trying to make this simple application. It's a tax calculator.
Two-dimensional arrays are a bit... well not easy for me to grasp yet. So my question is: can you take a look at my code and give me hints on how to solve this issue?
When I run the code in the Labelbox I get a result of 0.00
Public Class PerrytownForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents IdFwtLabel As System.Windows.Forms.Label
Friend WithEvents FwtLabel As System.Windows.Forms.Label
Friend WithEvents CalculateButton As System.Windows.Forms.Button
Friend WithEvents ExitButton As System.Windows.Forms.Button
Friend WithEvents StatusGroupBox As System.Windows.Forms.GroupBox
Friend WithEvents MarriedRadioButton As System.Windows.Forms.RadioButton
Friend WithEvents SingleRadioButton As System.Windows.Forms.RadioButton
Friend WithEvents IdTaxableLabel As System.Windows.Forms.Label
Friend WithEvents TaxableTextBox As System.Windows.Forms.TextBox
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.IdTaxableLabel = New System.Windows.Forms.Label()
Me.StatusGroupBox = New System.Windows.Forms.GroupBox()
Me.MarriedRadioButton = New System.Windows.Forms.RadioButton()
Me.SingleRadioButton = New System.Windows.Forms.RadioButton()
Me.TaxableTextBox = New System.Windows.Forms.TextBox()
Me.IdFwtLabel = New System.Windows.Forms.Label()
Me.FwtLabel = New System.Windows.Forms.Label()
Me.CalculateButton = New System.Windows.Forms.Button()
Me.ExitButton = New System.Windows.Forms.Button()
Me.StatusGroupBox.SuspendLayout()
Me.SuspendLayout()
'
'IdTaxableLabel
'
Me.IdTaxableLabel.AutoSize = True
Me.IdTaxableLabel.Location = New System.Drawing.Point(24, 24)
Me.IdTaxableLabel.Name = "IdTaxableLabel"
Me.IdTaxableLabel.Size = New System.Drawing.Size(99, 16)
Me.IdTaxableLabel.TabIndex = 0
Me.IdTaxableLabel.Text = "&Taxable wages:"
'
'StatusGroupBox
'
Me.StatusGroupBox.Controls.Add(Me.MarriedRadioButton)
Me.StatusGroupBox.Controls.Add(Me.SingleRadioButton)
Me.StatusGroupBox.Location = New System.Drawing.Point(184, 24)
Me.StatusGroupBox.Name = "StatusGroupBox"
Me.StatusGroupBox.Size = New System.Drawing.Size(95, 88)
Me.StatusGroupBox.TabIndex = 2
Me.StatusGroupBox.TabStop = False
Me.StatusGroupBox.Text = "Status"
'
'MarriedRadioButton
'
Me.MarriedRadioButton.Checked = True
Me.MarriedRadioButton.Location = New System.Drawing.Point(8, 21)
Me.MarriedRadioButton.Name = "MarriedRadioButton"
Me.MarriedRadioButton.Size = New System.Drawing.Size(80, 24)
Me.MarriedRadioButton.TabIndex = 0
Me.MarriedRadioButton.TabStop = True
Me.MarriedRadioButton.Text = "&Married"
'
'SingleRadioButton
'
Me.SingleRadioButton.Location = New System.Drawing.Point(8, 50)
Me.SingleRadioButton.Name = "SingleRadioButton"
Me.SingleRadioButton.Size = New System.Drawing.Size(80, 24)
Me.SingleRadioButton.TabIndex = 1
Me.SingleRadioButton.Text = "&Single"
'
'TaxableTextBox
'
Me.TaxableTextBox.Location = New System.Drawing.Point(24, 40)
Me.TaxableTextBox.Name = "TaxableTextBox"
Me.TaxableTextBox.Size = New System.Drawing.Size(136, 23)
Me.TaxableTextBox.TabIndex = 1
'
'IdFwtLabel
'
Me.IdFwtLabel.AutoSize = True
Me.IdFwtLabel.Location = New System.Drawing.Point(24, 80)
Me.IdFwtLabel.Name = "IdFwtLabel"
Me.IdFwtLabel.Size = New System.Drawing.Size(146, 16)
Me.IdFwtLabel.TabIndex = 5
Me.IdFwtLabel.Text = "Federal withholding tax:"
'
'FwtLabel
'
Me.FwtLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.FwtLabel.Location = New System.Drawing.Point(24, 96)
Me.FwtLabel.Name = "FwtLabel"
Me.FwtLabel.Size = New System.Drawing.Size(136, 23)
Me.FwtLabel.TabIndex = 6
Me.FwtLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'CalculateButton
'
Me.CalculateButton.Location = New System.Drawing.Point(184, 120)
Me.CalculateButton.Name = "CalculateButton"
Me.CalculateButton.Size = New System.Drawing.Size(96, 25)
Me.CalculateButton.TabIndex = 3
Me.CalculateButton.Text = "&Calculate Tax"
'
'ExitButton
'
Me.ExitButton.Location = New System.Drawing.Point(184, 152)
Me.ExitButton.Name = "ExitButton"
Me.ExitButton.Size = New System.Drawing.Size(96, 25)
Me.ExitButton.TabIndex = 4
Me.ExitButton.Text = "E&xit"
'
'PerrytownForm
'
Me.AcceptButton = Me.CalculateButton
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 16)
Me.ClientSize = New System.Drawing.Size(312, 205)
Me.Controls.Add(Me.StatusGroupBox)
Me.Controls.Add(Me.ExitButton)
Me.Controls.Add(Me.CalculateButton)
Me.Controls.Add(Me.FwtLabel)
Me.Controls.Add(Me.IdFwtLabel)
Me.Controls.Add(Me.TaxableTextBox)
Me.Controls.Add(Me.IdTaxableLabel)
Me.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "PerrytownForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Perrytown Gift Shop"
Me.StatusGroupBox.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
'declare form-level arrays
Private msngSingle(,) As Single = {{51, 0, 0, 0},
{552, 0, 0.15, 51},
{1196, 75.15, 0.28, 552},
{2662, 255.47, 0.31, 1196},
{5750, 709.93, 0.36, 2662},
{99999, 1821.61, 0.396, 5750}}
Private msngMarried(,) As Single = {{124, 0, 0, 0},
{960, 0, 0.15, 124},
{2023, 124.4, 0.28, 960},
{3292, 423.04, 0.31, 2023},
{5809, 816.43, 0.36, 3292},
{99999, 1722.55, 0.396, 5809}}
Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub TaxableTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TaxableTextBox.Enter
Me.TaxableTextBox.SelectAll()
End Sub
Private Sub ClearLabels(ByVal sender As Object, ByVal e As System.EventArgs) Handles MarriedRadioButton.Click, SingleRadioButton.Click, TaxableTextBox.TextChanged
Me.FwtLabel.Text = ""
End Sub
Private Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.Click
Dim sngTaxTable(5, 3) As Single
Dim sngTaxable, sngFwt As Single, intRow As Integer
Dim blnFound As Boolean
'assign taxable wages to a variable
sngTaxable = Val(Me.TaxableTextBox.Text)
'determine appropriate array
If Me.SingleRadioButton.Checked = True Then
sngTaxable = msngSingle
Else
sngTaxable = msngMarried
End If
'search for taxable wages in the first column in the array
Do While intRow < 6 AndAlso blnFound = False
If sngTaxable <= sngTaxTable(intRow, 0) Then
'calculate the fwt
sngFwt = sngTaxTable(intRow, 1) _
+ sngTaxTable(intRow, 2) _
* (sngTaxable - sngTaxTable(intRow, 3))
blnFound = True
Else
intRow = intRow + 1
End If
Loop
'display the fwt
Me.FwtLabel.Text = Format(sngFwt, "currency")
End Sub
End Class
I tried the code for myself and found some mistake: You forgot the letter "T"
If Me.SingleRadioButton.Checked = True Then
sngTaxable = msngSingle
Else
sngTaxable = msngMarried
End If
needs to be
If Me.SingleRadioButton.Checked = True Then
sngTaxTable = msngSingle
Else
sngTaxTable = msngMarried
End If
If I change this, the code will work and give some results, if I try to enter some numbers.
If they are too little or big, the program doesn't do anything. I don't know if this is intentional, but maybe a little error output (MsgBox etc) could be nice.

Using PC name by default

I finished my Chat over LAN project and everything work great,
but i have problem here,I don't want users put their name every time they want to send msgs over LAN, I want the program use the PC name by default, so in chat section the PC name will appear automatically, Can someone help me in this!
& this is my code
Imports System.DirectoryServices
Imports System.Net
Imports System.IO
Imports System.Net.Sockets
Imports MSTSCLib
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
Friend WithEvents txtPCName As System.Windows.Forms.TextBox
Friend WithEvents txtSend As System.Windows.Forms.TextBox
Friend WithEvents CmdSend As System.Windows.Forms.Button
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents txtPCIPadd As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents txtUsername As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents txtConversation As System.Windows.Forms.TextBox
Friend WithEvents txttempmsg As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain))
Me.CmdSend = New System.Windows.Forms.Button()
Me.TreeView1 = New System.Windows.Forms.TreeView()
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.txtPCName = New System.Windows.Forms.TextBox()
Me.txtSend = New System.Windows.Forms.TextBox()
Me.txtPCIPadd = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.txtUsername = New System.Windows.Forms.TextBox()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.txtConversation = New System.Windows.Forms.TextBox()
Me.txttempmsg = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'CmdSend
'
Me.CmdSend.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.CmdSend.Location = New System.Drawing.Point(404, 265)
Me.CmdSend.Name = "CmdSend"
Me.CmdSend.Size = New System.Drawing.Size(55, 52)
Me.CmdSend.TabIndex = 0
Me.CmdSend.Text = "&Send"
'
'TreeView1
'
Me.TreeView1.ImageIndex = 0
Me.TreeView1.ImageList = Me.ImageList1
Me.TreeView1.Location = New System.Drawing.Point(291, 10)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.SelectedImageIndex = 0
Me.TreeView1.Size = New System.Drawing.Size(168, 234)
Me.TreeView1.TabIndex = 1
'
'ImageList1
'
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
Me.ImageList1.Images.SetKeyName(0, "")
'
'txtPCName
'
Me.txtPCName.Location = New System.Drawing.Point(108, 34)
Me.txtPCName.Name = "txtPCName"
Me.txtPCName.ReadOnly = True
Me.txtPCName.Size = New System.Drawing.Size(136, 20)
Me.txtPCName.TabIndex = 2
'
'txtSend
'
Me.txtSend.Location = New System.Drawing.Point(12, 266)
Me.txtSend.Multiline = True
Me.txtSend.Name = "txtSend"
Me.txtSend.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtSend.Size = New System.Drawing.Size(386, 52)
Me.txtSend.TabIndex = 3
'
'txtPCIPadd
'
Me.txtPCIPadd.Location = New System.Drawing.Point(108, 58)
Me.txtPCIPadd.Name = "txtPCIPadd"
Me.txtPCIPadd.Size = New System.Drawing.Size(136, 20)
Me.txtPCIPadd.TabIndex = 6
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(13, 59)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(71, 15)
Me.Label2.TabIndex = 7
Me.Label2.Text = "IP Address :"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(12, 247)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(58, 15)
Me.Label3.TabIndex = 9
Me.Label3.Text = "Message"
'
'Timer1
'
'
'txtUsername
'
Me.txtUsername.Location = New System.Drawing.Point(108, 10)
Me.txtUsername.Name = "txtUsername"
Me.txtUsername.Size = New System.Drawing.Size(136, 20)
Me.txtUsername.TabIndex = 10
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(13, 14)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(70, 15)
Me.Label4.TabIndex = 11
Me.Label4.Text = "Your name:"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label5.Location = New System.Drawing.Point(13, 35)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(44, 15)
Me.Label5.TabIndex = 12
Me.Label5.Text = "Buddy:"
'
'txtConversation
'
Me.txtConversation.BackColor = System.Drawing.Color.White
Me.txtConversation.Location = New System.Drawing.Point(15, 84)
Me.txtConversation.Multiline = True
Me.txtConversation.Name = "txtConversation"
Me.txtConversation.ReadOnly = True
Me.txtConversation.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtConversation.Size = New System.Drawing.Size(270, 160)
Me.txtConversation.TabIndex = 14
'
'txttempmsg
'
Me.txttempmsg.Enabled = False
Me.txttempmsg.Location = New System.Drawing.Point(12, 342)
Me.txttempmsg.Multiline = True
Me.txttempmsg.Name = "txttempmsg"
Me.txttempmsg.Size = New System.Drawing.Size(212, 23)
Me.txttempmsg.TabIndex = 15
Me.txttempmsg.Visible = False
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ButtonFace
Me.ClientSize = New System.Drawing.Size(471, 329)
Me.Controls.Add(Me.txttempmsg)
Me.Controls.Add(Me.txtConversation)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.txtUsername)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtPCIPadd)
Me.Controls.Add(Me.txtSend)
Me.Controls.Add(Me.txtPCName)
Me.Controls.Add(Me.TreeView1)
Me.Controls.Add(Me.CmdSend)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmMain"
Me.Text = "KiWi Messenger"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Dim listerner As New TcpListener(44444)
Dim client As TcpClient
Dim client2 As TcpClient
Dim message As String = ""
Dim tts As Object
Dim Sound As New System.Media.SoundPlayer()
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
listerner.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TextBox1.Selectionstart = TextBox1.TextLength
'TextBox1.ScrollToCaret()
Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry()
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Dim newNode As New TreeNode(childEntry.Name)
Select Case childEntry.SchemaClassName
Case "Domain"
Dim ParentDomain As New TreeNode(childEntry.Name)
TreeView1.Nodes.AddRange(New TreeNode() {ParentDomain})
Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry()
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children
Dim newNode1 As New TreeNode(SubChildEntry.Name)
Select Case SubChildEntry.SchemaClassName
Case "Computer"
ParentDomain.Nodes.Add(newNode1)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories")
Finally
ParentEntry = Nothing
End Try
listerner.Start()
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSend.Click
' Shell("net send " & txtcomputer.Text & " " & txtmessage.Text)
Try
If txtPCIPadd.Text = "" Or txtUsername.Text = "" Or txtSend.Text = "" Then
MsgBox("Sorry Incomplete data")
Else
client = New TcpClient(txtPCIPadd.Text, 44444)
Dim writer As New StreamWriter(client.GetStream())
txttempmsg.Text = (txtSend.Text)
writer.Write(txtUsername.Text + " says: " + txtSend.Text)
txtConversation.Text = (txtConversation.Text + txtUsername.Text + " says: " + txttempmsg.Text + vbCrLf)
'txtmsg.Text="You:" + txtmessage.Text)
writer.Flush()
txtSend.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
txtPCName.Text = TreeView1.SelectedNode.Text
txtPCIPadd.Text = GetIPAddress(txtPCName.Text)
End Sub
Function GetIPAddress(ByVal CompName As String) As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
Try
With System.Net.Dns.GetHostByName(CompName)
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
Catch Excep As Exception
MsgBox(Excep.Message, MsgBoxStyle.OkOnly, "Lan Messenger")
Finally
End Try
End Function
Private Sub CmdPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Shell("PING " & txtPCIPadd.Text)
End Sub
'Shell("net send ALL " & txtmessage.Text)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
If listerner.Pending = True Then
message = ""
client = listerner.AcceptTcpClient
Dim reader As New StreamReader(client.GetStream())
While reader.Peek > -1
message = message + Convert.ToChar(reader.Read()).ToString
End While
Me.Focus()
txtConversation.Text = (txtConversation.Text + message + vbCrLf)
txtConversation.SelectionStart = txtConversation.TextLength
txtConversation.ScrollToCaret()
'txtmsg.Text="You:" + txtmessage.Text)
My.Computer.Audio.Play(My.Resources.alert, AudioPlayMode.Background)
Sound.Load()
Sound.Play()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Function c() As String
Throw New NotImplementedException
End Function
Private Sub txtUsername_TextChanged(sender As Object, e As EventArgs) Handles txtUsername.TextChanged
End Sub
End Class
You can retrieve the computer's name by using
System.Environment.MachineName
...of which you can assign to a variable, which in your instance would be:
txtUsername.Text = System.Environment.MachineName
Alternatively if you like doing things the long-winded way, you can use the WMI (Windows Management Instrumentation), as per se:
Dim details() As String = {"Name"}
Dim wmiItems As Dictionary(Of String, String)
wmiItems = WMI.GetWMISettingsDictionary("Win32_ComputerSystem", details)
For Each kvp As KeyValuePair(Of String, String) In wmiItems
txtUsername.Text = kvp.Value
Next
You can also get other system information in the same way, such as the make and model; refer to the documentation for this.
To use WMI you must refer to the System.Management library, place the following at the top of the code file:
Imports System.Management

VB.Net Designer Error (Value of type 'String' cannot be converted to 'System.Windows.Forms.DataGridViewTextBoxColumn'.)

I have a datagrid on a form named frmTeacherload and suddenly when I run the code it came up with this error Value of type 'String' cannot be converted to 'System.Windows.Forms.DataGridViewTextBoxColumn'. on the designer of vb. Here is my code guys I hope you can help me thanks in advance
designer code
_
Partial Class frmTeacherload
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.lblBack = New System.Windows.Forms.LinkLabel()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.DataGridView2 = New System.Windows.Forms.DataGridView()
Me.Name = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TblteacherloadDataSet2 = New WindowsApplication1.tblteacherloadDataSet2()
Me.TblteacherloadDataSet1 = New WindowsApplication1.tblteacherloadDataSet1()
Me.TblteacherloadTableAdapter = New WindowsApplication1.tblteacherloadDataSet1TableAdapters.tblteacherloadTableAdapter()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Label5 = New System.Windows.Forms.Label()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.Label6 = New System.Windows.Forms.Label()
Me.TextBox4 = New System.Windows.Forms.TextBox()
Me.Label7 = New System.Windows.Forms.Label()
Me.TextBox5 = New System.Windows.Forms.TextBox()
Me.Label8 = New System.Windows.Forms.Label()
Me.TextBox6 = New System.Windows.Forms.TextBox()
Me.Label9 = New System.Windows.Forms.Label()
Me.TextBox7 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.TblteacherloadTableAdapter1 = New WindowsApplication1.tblteacherloadDataSet2TableAdapters.tblteacherloadTableAdapter()
Me.TblteacherloadDataSet3 = New WindowsApplication1.tblteacherloadDataSet3()
Me.BindingSource1 = New System.Windows.Forms.BindingSource(Me.components)
Me.TblteacherloadTableAdapter2 = New WindowsApplication1.tblteacherloadDataSet3TableAdapters.tblteacherloadTableAdapter()
Me.DataGridViewTextBoxColumn1 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.NameDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn2 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn3 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn4 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn5 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn6 = New System.Windows.Forms.DataGridViewTextBoxColumn()
CType(Me.DataGridView2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.TblteacherloadDataSet2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.TblteacherloadDataSet1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.TblteacherloadDataSet3, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.BindingSource1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("Lucida Calligraphy", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(610, 18)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(217, 31)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Teacher's Load"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(22, 74)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(125, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Choose Teachers Name:"
'
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(149, 70)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
Me.ComboBox1.TabIndex = 2
'
'lblBack
'
Me.lblBack.AutoSize = True
Me.lblBack.Location = New System.Drawing.Point(22, 30)
Me.lblBack.Name = "lblBack"
Me.lblBack.Size = New System.Drawing.Size(50, 13)
Me.lblBack.TabIndex = 94
Me.lblBack.TabStop = True
Me.lblBack.Text = "<<<Back"
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.Black
Me.Panel1.Location = New System.Drawing.Point(549, 52)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(272, 10)
Me.Panel1.TabIndex = 95
'
'DataGridView2
'
Me.DataGridView2.AutoGenerateColumns = False
Me.DataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.DataGridView2.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Name, Me.DataGridViewTextBoxColumn1, Me.NameDataGridViewTextBoxColumn, Me.DataGridViewTextBoxColumn2, Me.DataGridViewTextBoxColumn3, Me.DataGridViewTextBoxColumn4, Me.DataGridViewTextBoxColumn5, Me.DataGridViewTextBoxColumn6})
Me.DataGridView2.DataSource = Me.BindingSource1
Me.DataGridView2.Location = New System.Drawing.Point(45, 97)
Me.DataGridView2.Name = "DataGridView2"
Me.DataGridView2.Size = New System.Drawing.Size(753, 178)
Me.DataGridView2.TabIndex = 96
'
'Name
'
Me.Name.DataPropertyName = "Name"
Me.Name.HeaderText = "Name"
Me.Name.Name = "Name"
'
'TblteacherloadDataSet2
'
Me.TblteacherloadDataSet2.DataSetName = "tblteacherloadDataSet2"
Me.TblteacherloadDataSet2.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
'TblteacherloadDataSet1
'
Me.TblteacherloadDataSet1.DataSetName = "tblteacherloadDataSet1"
Me.TblteacherloadDataSet1.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
'TblteacherloadTableAdapter
'
Me.TblteacherloadTableAdapter.ClearBeforeFill = True
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(123, 303)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(100, 20)
Me.TextBox1.TabIndex = 97
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(33, 306)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(18, 13)
Me.Label3.TabIndex = 98
Me.Label3.Text = "ID"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(33, 351)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(85, 13)
Me.Label4.TabIndex = 100
Me.Label4.Text = "Teacher's Name"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(123, 348)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(100, 20)
Me.TextBox2.TabIndex = 99
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(337, 310)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(43, 13)
Me.Label5.TabIndex = 104
Me.Label5.Text = "Subject"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(123, 393)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(100, 20)
Me.TextBox3.TabIndex = 103
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(33, 394)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(43, 13)
Me.Label6.TabIndex = 102
Me.Label6.Text = "Section"
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(427, 303)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(100, 20)
Me.TextBox4.TabIndex = 101
'
'Label7
'
Me.Label7.AutoSize = True
Me.Label7.Location = New System.Drawing.Point(337, 393)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(30, 13)
Me.Label7.TabIndex = 108
Me.Label7.Text = "Time"
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(427, 345)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(100, 20)
Me.TextBox5.TabIndex = 107
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(337, 348)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(26, 13)
Me.Label8.TabIndex = 106
Me.Label8.Text = "Day"
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(427, 394)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(100, 20)
Me.TextBox6.TabIndex = 105
'
'Label9
'
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(588, 306)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(35, 13)
Me.Label9.TabIndex = 112
Me.Label9.Text = "Room"
'
'TextBox7
'
Me.TextBox7.Location = New System.Drawing.Point(678, 303)
Me.TextBox7.Name = "TextBox7"
Me.TextBox7.Size = New System.Drawing.Size(100, 20)
Me.TextBox7.TabIndex = 111
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(591, 435)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(94, 30)
Me.Button1.TabIndex = 113
Me.Button1.Text = "SUBMIT"
Me.Button1.UseVisualStyleBackColor = True
'
'TblteacherloadTableAdapter1
'
Me.TblteacherloadTableAdapter1.ClearBeforeFill = True
'
'TblteacherloadDataSet3
'
Me.TblteacherloadDataSet3.DataSetName = "tblteacherloadDataSet3"
Me.TblteacherloadDataSet3.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
'BindingSource1
'
Me.BindingSource1.DataMember = "tblteacherload"
Me.BindingSource1.DataSource = Me.TblteacherloadDataSet3
'
'TblteacherloadTableAdapter2
'
Me.TblteacherloadTableAdapter2.ClearBeforeFill = True
'
'DataGridViewTextBoxColumn1
'
Me.DataGridViewTextBoxColumn1.DataPropertyName = "ID"
Me.DataGridViewTextBoxColumn1.HeaderText = "ID"
Me.DataGridViewTextBoxColumn1.Name = "DataGridViewTextBoxColumn1"
'
'NameDataGridViewTextBoxColumn
'
Me.NameDataGridViewTextBoxColumn.DataPropertyName = "Name"
Me.NameDataGridViewTextBoxColumn.HeaderText = "Name"
Me.NameDataGridViewTextBoxColumn.Name = "NameDataGridViewTextBoxColumn"
'
'DataGridViewTextBoxColumn2
'
Me.DataGridViewTextBoxColumn2.DataPropertyName = "Section"
Me.DataGridViewTextBoxColumn2.HeaderText = "Section"
Me.DataGridViewTextBoxColumn2.Name = "DataGridViewTextBoxColumn2"
'
'DataGridViewTextBoxColumn3
'
Me.DataGridViewTextBoxColumn3.DataPropertyName = "Subject"
Me.DataGridViewTextBoxColumn3.HeaderText = "Subject"
Me.DataGridViewTextBoxColumn3.Name = "DataGridViewTextBoxColumn3"
'
'DataGridViewTextBoxColumn4
'
Me.DataGridViewTextBoxColumn4.DataPropertyName = "Day"
Me.DataGridViewTextBoxColumn4.HeaderText = "Day"
Me.DataGridViewTextBoxColumn4.Name = "DataGridViewTextBoxColumn4"
'
'DataGridViewTextBoxColumn5
'
Me.DataGridViewTextBoxColumn5.DataPropertyName = "Time"
Me.DataGridViewTextBoxColumn5.HeaderText = "Time"
Me.DataGridViewTextBoxColumn5.Name = "DataGridViewTextBoxColumn5"
'
'DataGridViewTextBoxColumn6
'
Me.DataGridViewTextBoxColumn6.DataPropertyName = "Room"
Me.DataGridViewTextBoxColumn6.HeaderText = "Room"
Me.DataGridViewTextBoxColumn6.Name = "DataGridViewTextBoxColumn6"
'
'frmTeacherload
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(839, 494)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.TextBox7)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.DataGridView2)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.lblBack)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "frmTeacherload"
Me.Text = "First Books Learning Center"
CType(Me.DataGridView2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.TblteacherloadDataSet2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.TblteacherloadDataSet1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.TblteacherloadDataSet3, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.BindingSource1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents frmTeacherload As System.Windows.Forms.Form
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents lblBack As System.Windows.Forms.LinkLabel
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents DataGridView2 As System.Windows.Forms.DataGridView
Friend WithEvents TblteacherloadDataSet1 As WindowsApplication1.tblteacherloadDataSet1
Friend WithEvents TblteacherloadBindingSource As System.Windows.Forms.BindingSource
Friend WithEvents TblteacherloadTableAdapter As WindowsApplication1.tblteacherloadDataSet1TableAdapters.tblteacherloadTableAdapter
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TblteacherloadDataSet2 As WindowsApplication1.tblteacherloadDataSet2
Friend WithEvents TblteacherloadBindingSource1 As System.Windows.Forms.BindingSource
Friend WithEvents TblteacherloadTableAdapter1 As WindowsApplication1.tblteacherloadDataSet2TableAdapters.tblteacherloadTableAdapter
Friend WithEvents IDDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Shadows WithEvents Name As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents SectionDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents SubjectDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DayDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TimeDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents RoomDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TblteacherloadDataSet3 As WindowsApplication1.tblteacherloadDataSet3
Friend WithEvents BindingSource1 As System.Windows.Forms.BindingSource
Friend WithEvents TblteacherloadTableAdapter2 As WindowsApplication1.tblteacherloadDataSet3TableAdapters.tblteacherloadTableAdapter
Friend WithEvents DataGridViewTextBoxColumn1 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents NameDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DataGridViewTextBoxColumn2 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DataGridViewTextBoxColumn3 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DataGridViewTextBoxColumn4 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DataGridViewTextBoxColumn5 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents DataGridViewTextBoxColumn6 As System.Windows.Forms.DataGridViewTextBoxColumn
End Class
frmTeacherload
Public Class frmTeacherload
Dim query As String
Dim y As String = "Provider=Microsoft.ACE.OLEDB.12.0;Password='';User ID=;Data Source='" & Application.StartupPath & "/tblteacherload.accdb';"
Dim database As New clsDatabase.OleDBase(y)
Private Sub lblBack_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblBack.LinkClicked
frmEnrollment.Show()
Me.Hide()
End Sub
Private Sub frmTeacherload_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TblteacherloadDataSet3.tblteacherload' table. You can move, or remove it, as needed.
Me.TblteacherloadTableAdapter2.Fill(Me.TblteacherloadDataSet3.tblteacherload)
'TODO: This line of code loads data into the 'TblteacherloadDataSet2.tblteacherload' table. You can move, or remove it, as needed.
Me.TblteacherloadTableAdapter1.Fill(Me.TblteacherloadDataSet2.tblteacherload)
'TODO: This line of code loads data into the 'TblteacherloadDataSet1.tblteacherload' table. You can move, or remove it, as needed.
Me.TblteacherloadTableAdapter.Fill(Me.TblteacherloadDataSet1.tblteacherload)
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub fillDataGridView2()
Try
Cursor = Cursors.WaitCursor
'=================================================
'eto lang naman ung mahalaga-> para ilabas sa datagridview ung laman ng table
query = "Select * From tblteacherload;" ' malamang eto ung query
database.ToDataGrid(Me.DataGridView2, query) ' eto naman ung pang-execute
'=================================================
Cursor = Cursors.Default
Catch ex As Exception
MessageBox.Show("Connection Failed")
Cursor = Cursors.Default
End Try
End Sub
'eto ung mga query, dapat maayos at tama lahat ng nakasulat., pag hindi error lalabas, magingat ka sa pag-dedeclare, tignan mo mabuti ung query para tama
Private Sub add_save()
query = "INSERT INTO `tblteacherload`(`ID`, `Name`, `Section`, `Subject`, `Day`,`Time`,`Room`) VALUES ('" _
& TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & TextBox6.Text & "', , '" & TextBox7.Text & "');"
database.ToDataGrid(Me.DataGridView2, query)
clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
add_save()
MsgBox("Saved Successfully", MsgBoxStyle.Information, "")
End Sub
Private Sub clear()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Sub
Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
Me.TblteacherloadTableAdapter1.FillBy(Me.TblteacherloadDataSet2.tblteacherload)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
The error is in this line
Me.Name = New System.Windows.Forms.DataGridViewTextBoxColumn()
You have a column on your DataGridView control named "Name" and the form has a property named "Name".
When the designer finds the line above it thinks that that's the property Name of the form.
If you look down the designer code you'll find this other line
Me.Name = "frmTeacherload"
To fix that error you have to rename the column.

WinForms Object Databinding Performance Issue

I have created a simple VB .NET Application. 1 Form with 2 TextBoxes bounded to a class with 2 properties, Property1 and Property2. If I input text in TextBox1, binding process causes reading of second property, Property2. Why? I don't want that if I change a property, all bounded controls updates their data.
Code:
' Class1.vb
Imports System.ComponentModel
Public Class Class1
Private property1Value As String
Public Property Property1() As String
Get
Return property1Value
End Get
Set(ByVal value As String)
property1Value = value
End Set
End Property
Private property2Value As String
Public Property Property2() As String
Get
Return property2Value
End Get
Set(ByVal value As String)
property2Value = value
End Set
End Property
End Class
' Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Richiesto da Progettazione Windows Form
Private components As System.ComponentModel.IContainer
'NOTA: la procedura che segue è richiesta da Progettazione Windows Form
'Può essere modificata in Progettazione Windows Form.
'Non modificarla nell'editor del codice.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Class1BindingSource = New System.Windows.Forms.BindingSource(Me.components)
CType(Me.Class1BindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.Class1BindingSource, "Property1", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(100, 22)
Me.TextBox1.TabIndex = 2
'
'TextBox2
'
Me.TextBox2.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.Class1BindingSource, "Property2", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
Me.TextBox2.Location = New System.Drawing.Point(12, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(100, 22)
Me.TextBox2.TabIndex = 3
'
'Class1BindingSource
'
Me.Class1BindingSource.DataSource = GetType(WindowsApplication1.Class1)
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(282, 255)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Class1BindingSource, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Class1BindingSource As System.Windows.Forms.BindingSource
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
End Class
' Form1.vb
Imports System.ComponentModel
Public Class Form1
Private Class1 As New Class1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Class1.Property1 = "Prop1"
Class1.Property2 = "Prop2"
Class1BindingSource.DataSource = Class1
End Sub
End Class