Hello guys/girl, how are You. I have one problem. I'm creating a exam system which should give 40 random questions from database table(mySQL). I managed to create (not perfect, still small problems with .possition and .size ) textboxes and checkboxex ( on button click event ). And I managed to get ONE (first row) data from my sql but then it stops. I cannot create more textboxes or checkboxex. See my code below. If You didnt fully understand what I want or what I need, please ask question and I'll give the asnwer.
CODE IN COMMENT ( SPAM ERROR )
1 1328 -
Imports System.Data.SqlClient
-
Public Class Form1
-
Dim cn As New SqlConnection("Data Source=192.168.0.45,1433;Network Library=DBMSSOCN;Initial Catalog=DB_GS-TMT_SSuite;User ID=itmahir;Password=itadmin;")
-
Private m_textboxes() As TextBox = {}
-
Private m_checkboxes() As CheckBox = {}
-
Dim i As Integer = m_textboxes.Length
-
Dim a As Integer = m_checkboxes.Length
-
Public Overrides Property AutoScroll As Boolean
-
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
*
-
ReDim Preserve m_textboxes(i)
-
m_textboxes(i) = New TextBox
-
With m_textboxes(i)
-
.Name = "TextBox" & i.ToString
-
.Text = "TextBox" & i.ToString
-
If m_textboxes.Length < 2 Then
-
.SetBounds(10, 10, 100, 20)
-
Else
-
.Left = m_textboxes(i - 1).Left
-
.Top = m_textboxes(i - 1).Top + m_textboxes(i - 1).Height + 4
-
.Size = m_textboxes(i - 1).Size
-
*
-
End If
-
.Tag = i
-
*
-
End With
-
AddHandler m_textboxes(i).TextChanged, AddressOf TextBox_TextChanged
-
Me.Controls.Add(m_textboxes(i))
-
CitacBaze()
-
ReDim Preserve m_checkboxes(a)
-
*
-
m_checkboxes(a) = New CheckBox
-
With m_checkboxes(a)
-
.Name = "CheckBox" & a.ToString
-
.Text = "CheckBox" & a.ToString
-
If m_checkboxes.Length < 2 Then
-
.SetBounds(135, 10, 100, 20)
-
Else
-
.RightToLeft = m_checkboxes(a - 1).RightToLeft
-
.Top = m_checkboxes(a - 1).Top + m_checkboxes(a - 1).Height + 4
-
.Size = New Size(20, 20)
-
*
-
End If
-
.Tag = a
-
End With
-
AddHandler m_checkboxes(a).CheckStateChanged, AddressOf CheckBox_CheckStateChanged
-
CitacOdgovora()
-
Me.Controls.Add(m_checkboxes(a))
-
*
-
End Sub
-
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
Dim txt As TextBox = DirectCast(sender, TextBox)
-
Debug.WriteLine(txt.Name & ": [" & txt.Text & "]")
-
End Sub
-
Private Sub CheckBox_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
Dim chB As CheckBox = DirectCast(sender, CheckBox)
-
Debug.WriteLine(chB.Name & ": [" & chB.Text & "]")
-
End Sub
-
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
-
*
-
Me.AutoScroll = True
-
*
-
-
End Sub
-
Public Sub CitacBaze()
-
cn.Open()
-
Dim cmd As New SqlCommand
-
Dim dadapter As New SqlDataAdapter
-
Dim datardr As SqlDataReader
-
Dim strSql As String
-
*
-
strSql = "SELECT * FROM TBL_Testiranje_Radnik"
-
cmd.CommandText = strSql
-
cmd.Connection = cn
-
dadapter.SelectCommand = cmd
-
datardr = cmd.ExecuteReader
-
If datardr.HasRows Then
-
datardr.Read()
-
With m_textboxes(i)
-
.Text = datardr("TekstPitanje")
-
*
-
End With
-
*
-
End If
-
cn.Close()
-
*
-
-
End Sub
-
Public Sub CitacOdgovora()
-
cn.Open()
-
Dim cmd As New SqlCommand
-
Dim dadapter As New SqlDataAdapter
-
Dim datardr As SqlDataReader
-
Dim strSql As String
-
*
-
strSql = "SELECT * FROM TBL_Testiranje_Radnik"
-
cmd.CommandText = strSql
-
cmd.Connection = cn
-
dadapter.SelectCommand = cmd
-
datardr = cmd.ExecuteReader
-
If datardr.HasRows Then
-
datardr.Read()
-
*
-
-
With m_checkboxes(a)
-
.Text = datardr("OdgovorA")
-
End With
-
*
-
End If
-
cn.Close()
-
*
-
-
End Sub
-
Public Sub KreiranjeTextBox()
-
ReDim Preserve m_textboxes(i)
-
m_textboxes(i) = New TextBox
-
With m_textboxes(i)
-
.Name = "TextBox" & i.ToString
-
.Text = "TextBox" & i.ToString
-
If m_textboxes.Length < 2 Then
-
.SetBounds(10, 10, 100, 20)
-
Else
-
.Left = m_textboxes(i - 1).Left
-
.Top = m_textboxes(i - 1).Top + m_textboxes(i - 1).Height + 4
-
.Size = m_textboxes(i - 1).Size
-
*
-
End If
-
.Tag = i
-
*
-
End With
-
AddHandler m_textboxes(i).TextChanged, AddressOf TextBox_TextChanged
-
Me.Controls.Add(m_textboxes(i))
-
CitacBaze()
-
End Sub
-
Public Sub KreiranjeCheckBoxova()
-
ReDim Preserve m_checkboxes(a)
-
*
-
m_checkboxes(a) = New CheckBox
-
With m_checkboxes(a)
-
.Name = "CheckBox" & a.ToString
-
.Text = "CheckBox" & a.ToString
-
If m_checkboxes.Length < 2 Then
-
.SetBounds(135, 10, 100, 20)
-
Else
-
.RightToLeft = m_checkboxes(a - 1).RightToLeft
-
.Top = m_checkboxes(a - 1).Top + m_checkboxes(a - 1).Height + 4
-
.Size = New Size(20, 20)
-
*
-
End If
-
.Tag = a
-
End With
-
AddHandler m_checkboxes(a).CheckStateChanged, AddressOf CheckBox_CheckStateChanged
-
CitacOdgovora()
-
Me.Controls.Add(m_checkboxes(a))
-
*
-
End Sub
-
End Class
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Victor |
last post by:
I have dynamically created n number of text boxes in a form like txtQL(1),
txtQL(2) , ...txtQL(n)
How can I retrieve the values in a loop? I'm confused as to how to approach
this! Please help.
...
|
by: Jake_adl |
last post by:
Is there any way to create a
Microsoft.Practices.EnterpriseLibrary.Data.Database object without reading
from a configuration file?
I am writing a utility that manages databases in SQL Server....
|
by: Brian Pittman |
last post by:
Hi,
How do you go about obtaining the text typed in a dynamic textbox when the
submit button is clicked.
Thanks Brian
'Add textbox to controls collection
Dim txtTextBox as TextBox = New...
|
by: Schapopa |
last post by:
Hello,
I have form where I want to display data from one record. So I created
stored procedure with parameter and I populated some dropdown boxes
with data, and now I would like to display that...
|
by: anniejacob |
last post by:
hi,
i would like to know how to bind my dynamic textboxes in C# to the database n get the value in my textboxes updated in my SQL database.
if someone could help me soon.
|
by: sakhan |
last post by:
Hello Friends,
I want to create a row of 10 textboxes each time I click the add button.
I want this to continue till it reaches five hundred
I am using AJAX for this.
It doesnot create 10...
|
by: manbassie |
last post by:
I have xml web service which returns a dataset. I have textboxes which need to be populated with this data and my problem is how to bind the data to the textboxes when the form loads and be able to...
|
by: nitin24x |
last post by:
hi, i need help ...ASp.net
i created one form including some labels and text boxes for example firstname, Lastname,city,country,phone no. etc and textboxes for each. i have one database,in that...
|
by: englishman69 |
last post by:
Hello,
I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |