Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Simple (I hope) looping issue
 

Simple (I hope) looping issue

I am trying to create a form which will be fed by an underlying database to create multiple form fields for each entry in an underlying database table. This is for a program to monitor patients under anesthesia, and prior to surgery, the doctor will choose which monitors they will be using. Then, on the actual monitor screen which will pop up every X minutes, there will be a text box and a check box for each chosen monitor. I am relatively new to VB, so I have tried to illustrate what I am needing but using the logic that I know from my previous life in PHP.

I am using DevExpress's layout control to place the form fields, so that is the code in the middle of the first loop (on_load), and I know that part works, I just need to know how to name the fields and then recover those fields and commit the values to the database. (the text boxes are added to the database, the check boxes are used to determine if an entry is made for that monitor- i.e. at the end of surgery if a monitor is turned off)

I know that my syntax for naming the fields is no where close to correct, and it probably would not work in PHP, but I remember doing something like this in a PHP application I built long ago.

How do I do this?????? Any help would be greatly appreciated!

Imports DevExpress.XtraLayout
Imports DevExpress.XtraEditors

Public Class frmMonitorRecord

    Private m_dtDataTable As New VDARSQLDATASET.Monitor_ValueDataTable
    Private tableAdapter As New VDARSQLDATASETTableAdapters.Monitor_ValueTableAdapter
    Private drDataRow As DataRow
    Private dtCaseMonitors As New VDARSQLDATASET.caseMonitorsDataTable
    Private taCaseMonitors As New VDARSQLDATASETTableAdapters.caseMonitorsTableAdapter
    Private caseMonitors As DataRow
    Private tableAdapterInsert As New VDARSQLDATASETTableAdapters.inductionMaint_ParameterValueTableAdapter

    Private Sub frmMonitorRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SystemSounds.Exclamation.Play()

        lblRecordTime.Text = CStr(frmMainForm.curTime) + CStr(" Minutes")

        dtCaseMonitors = taCaseMonitors.GetDataByCaseID(frmMainForm.SelectedCase)

        For i = 0 To dtCaseMonitors.Rows.Count - 1 Step 1
            caseMonitors = dtCaseMonitors.Rows(i)

            'Create a layout item and add it to the root group.    
            Dim item As LayoutControlItem = LayoutControl1.Root.AddItem
            ' Set the item's Control and caption.
            item.Name = "Layout Item " + i
            item.TextVisible = False
            Dim spinBox = New SpinEdit()
            spinBox.Name = "spn" + i
            item.Control = spinBox

            'Create a layout item and add it to the root group.    
            Dim item2 As LayoutControlItem = LayoutControl1.Root.AddItem
            ' Set the item's Control and caption.
            item2.Name = "Layout Item " + i + "b"
            item2.TextVisible = True
            Dim chkBox = New CheckEdit()
            chkBox.Name = "chk" + i
            item2.Control = chkBox
            item2.Text = caseMonitors("monitorName")
            item2.TextLocation = DevExpress.Utils.Locations.Right
            item2.Move(item, Utils.InsertType.Right)

            m_dtDataTable = tableAdapter.GetDataByIndvParameter(frmMainForm.SelectedCase, frmMainForm.prevTime, caseMonitors("monitorID"))
            If Not frmMainForm.prevTime = Nothing Then
                If Not m_dtDataTable.Rows.Count = 0 Then
                    drDataRow = m_dtDataTable.Rows(0)
                    spinBox.Value = CDec(drDataRow("parameterValue"))
                    chkBox.CheckState = CheckState.Checked
                Else
                    spinBox.Value = Nothing
                    chkBox.CheckState = CheckState.Unchecked
                End If
            End If
        Next
    End Sub

    Private Sub btnAccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccept.Click

        For i As Integer = 0 To dtCaseMonitors.Rows.Count - 1 Step 1
            If "chk" + i.CheckState = CheckState.Checked Then
                tableAdapterInsert.InsertQuery(frmMainForm.SelectedCase, 1, frmMainForm.curTime, spin + i.Value)
            End If
        Next

        Me.Close()

    End Sub

    Private Sub tmrSound_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSound.Tick
        SystemSounds.Exclamation.Play()

    End Sub
End Class
scholzr  Tuesday, November 24, 2009 5:06 PM
Hi,

Your question is very much around DEVEXpress controls.

Will this is a Microsoft Forum.

That makes it difficult to answer.

However, keep in mind that for putting controls on a form you have to add them to the controls collection in a form.

me.Controls.ADD(theControl)

A control can be a containter as well

TheControl.Controls.Add(A childControl)

Every controls has a location wich is set with a Point Object

theControl.Location = new Point(10,10)


and a size property

theControl.Size - new Size(10,70)

With this information you should be able to achieve your result.


Success
Cor
Cor Ligthert  Tuesday, November 24, 2009 7:12 PM
So then am I understanding you correctly that on the form load, I can add a control to the me.controls collection, and if I set the location, these will each be displayed on the form. I should then be able to loop through the controls collection to run my database insert query on each control in the collection?

Would it look something like this (Very oversimplified, not correct schema I know)?

Private Sub frmMonitorRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     For Each datarow as datarow
          me.Controls.ADD(theControl)
          theControl.Location = new Point (10,10)
          theControl.Size = new Size(10,70)
     Next
End Sub

Private Sub btnAccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccept.Click
     for Each me.Controls as control
           tableAdapter.databaseQuery(theControl.Value)
     Next
End Sub
I know that I will need to set the location by calculating the previous location and adding to it. I can handle that. In terms of control name, do I need to figure out a way to name each something differant? If so, can I use a database row for that (i.e. dataRow("monitorName") )? If that won't work, how do I specify a unique control name for each?
scholzr  Tuesday, November 24, 2009 7:50 PM
Hi scholzr,

If i understand your correctly, you want to add controls to a form in runtime.
Here is an example
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For i As Integer = 0 To 2
            Dim llabel As LinkLabel = New LinkLabel
            llabel.Name = "ll" & i
            llabel.Text = "www.google.com"
            llabel.Location = New Point(0, i * llabel.Height)
            Me.Controls.Add(llabel)
        Next

        Dim count As Integer = 0
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is LinkLabel Then
                count += 1
            End If
        Next

    End Sub
And to my understanding, you should name each control different, and of course you can get name from database.
But you need to retrieve it first, you can look into the following example
FAQ: How do I make a basic Data Access application
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c27538e2-44d7-4cb9-9141-ed7ee733bf80

Besides, you can get better support in Devexpress forum
http://community.devexpress.com/forums/

Hope this helps

Regards
Jeff Shan


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Jeff Shan  20 hours 31 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• How to force controls to stay the same size...
• Broadcast a message to Applications through the network
• How to get control styles
• GridView1 first row always selected
• Text not showing up in Listbox
• Retrieving PDF document stored in SQL
• Problems Publishing / Configuring Application Files in VB.Net program?
• Attempted to read or write protected memory. This is often an indication that other memory is corrupt. (or) Overflow exception
• Launch My Program after it has installed ...
• Data not being committed to database