Click here to Skip to main content
16,004,406 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Need to talk to USB serial adapter but no port data available on laptop Pin
KarltheSaabNut13-Jul-15 6:13
professionalKarltheSaabNut13-Jul-15 6:13 
GeneralRe: Need to talk to USB serial adapter but no port data available on laptop Pin
Michael_Davies13-Jul-15 6:19
Michael_Davies13-Jul-15 6:19 
GeneralRe: Need to talk to USB serial adapter but no port data available on laptop Pin
KarltheSaabNut13-Jul-15 6:28
professionalKarltheSaabNut13-Jul-15 6:28 
QuestionData Access Layer using Entity Framework 6.0, Record Inserts Pin
jkirkerx12-Jul-15 12:03
professionaljkirkerx12-Jul-15 12:03 
Answer[SOLVED] Pin
jkirkerx12-Jul-15 12:50
professionaljkirkerx12-Jul-15 12:50 
QuestionProblem referencing controls of a dynamically created form. Pin
Abcecedarian11-Jul-15 11:14
Abcecedarian11-Jul-15 11:14 
AnswerRe: Problem referencing controls of a dynamically created form. Pin
Wes Aday11-Jul-15 15:08
professionalWes Aday11-Jul-15 15:08 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Abcecedarian11-Jul-15 20:22
Abcecedarian11-Jul-15 20:22 
I am sorry indeed! I didn't post the code as it is quite long. However, I have shortened it to a good extent now.
Here is my code:
====================================================

Private Sub DGVClients_RowHeaderMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGVClients.RowHeaderMouseClick

MessageBox.Show("You have selected row No. " & e.RowIndex.ToString())
Dim txtClientId As New TextBox
With txtClientId
.Size = New System.Drawing.Size(150, 20)
.Location = New System.Drawing.Size(150, 20)
End With
Dim txtClientName As New TextBox
With txtClientName
.Size = New System.Drawing.Size(150, 20)
.Location = New System.Drawing.Size(150, 45)
End With
Dim txtClientAddress As New TextBox
With txtClientAddress
.Size = New System.Drawing.Size(200, 20)
.Location = New System.Drawing.Size(150, 75)
End With

Dim lblCId, lblCName, lblCAdd As Label
lblCName = New Label
lblCId = New Label
lblCAdd = New Label

With lblCId
.Text = "Client Id:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 20)
.Show()
End With
With lblCName
.Text = "Client Name:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 45)
.Show()
End With
With lblCAdd
.Text = "Client Address:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 75)
.Show()
End With

Dim btnAddC As Button
btnAddC = New Button
With btnAddC
.Text = "Add Client"
.Font = New Font("Arial", 10)
.Size = New System.Drawing.Size(100, 35)
.Location = New System.Drawing.Size(20, 260)
End With
AddHandler btnAddC.Click, AddressOf Me.AddNewClient


Dim curForm As Form = New Form
With curForm
'Definition of the form
.Text = "Add / Update Client"
.Size = New System.Drawing.Size(400, 350)
.StartPosition = FormStartPosition.CenterScreen
.Show()
.Controls.Add(lblCId)
.Controls.Add(txtClientId)
.Controls.Add(lblCName)
.Controls.Add(txtClientName)
.Controls.Add(lblCAdd)
.Controls.Add(txtClientAddress)
.Controls.Add(lblCCity)

.Controls.Add(btnAddC)

End With

End Sub

Friend Sub AddNewClient(ByVal sender As System.Object, ByVal e As System.EventArgs)

'MessageBox.Show("Button AddClient clicked!")
MsgBox(txtClientId.ToString)

End Sub
=======================================================

It is the "Sub AddNewClient()" that I am struck up in. The controls of the created form are inaccessible in the buttonClick event handling sub. Also, if I DirectCast the controls, nullrefernceexception is thrown.

I appreciate if you could please sort it out for me.

Many thanks!

modified 12-Jul-15 2:32am.

AnswerRe: Problem referencing controls of a dynamically created form. Pin
Ralf Meier11-Jul-15 23:54
mveRalf Meier11-Jul-15 23:54 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Abcecedarian12-Jul-15 0:47
Abcecedarian12-Jul-15 0:47 
AnswerRe: Problem referencing controls of a dynamically created form. Pin
Ralf Meier12-Jul-15 1:02
mveRalf Meier12-Jul-15 1:02 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Abcecedarian12-Jul-15 14:59
Abcecedarian12-Jul-15 14:59 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Ralf Meier12-Jul-15 22:53
mveRalf Meier12-Jul-15 22:53 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Abcecedarian13-Jul-15 0:30
Abcecedarian13-Jul-15 0:30 
GeneralRe: Problem referencing controls of a dynamically created form. Pin
Ralf Meier13-Jul-15 8:09
mveRalf Meier13-Jul-15 8:09 
QuestionHow to fix a lagging after but a flickering createparams Code Pin
Mohamed Hamdy10-Jul-15 7:09
Mohamed Hamdy10-Jul-15 7:09 
QuestionRe: How to fix a lagging after but a flickering createparams Code Pin
Eddy Vluggen10-Jul-15 7:16
professionalEddy Vluggen10-Jul-15 7:16 
AnswerRe: How to fix a lagging after but a flickering createparams Code Pin
Mohamed Hamdy10-Jul-15 12:40
Mohamed Hamdy10-Jul-15 12:40 
GeneralRe: How to fix a lagging after but a flickering createparams Code Pin
Richard MacCutchan10-Jul-15 21:19
mveRichard MacCutchan10-Jul-15 21:19 
QuestionConnect to remote sql server Pin
satc9-Jul-15 18:05
satc9-Jul-15 18:05 
AnswerRe: Connect to remote sql server Pin
Wendelius9-Jul-15 18:21
mentorWendelius9-Jul-15 18:21 
GeneralRe: Connect to remote sql server Pin
satc9-Jul-15 19:47
satc9-Jul-15 19:47 
GeneralRe: Connect to remote sql server Pin
Wendelius9-Jul-15 20:06
mentorWendelius9-Jul-15 20:06 
GeneralRe: Connect to remote sql server Pin
satc9-Jul-15 20:19
satc9-Jul-15 20:19 
AnswerRe: Connect to remote sql server Pin
PIEBALDconsult9-Jul-15 18:31
mvePIEBALDconsult9-Jul-15 18:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.