Hi from a newbie,
I face a problem trying to take the values from a variety of controls that I create dynamically using some data from my database.
For example
I have a treeview and if I click on the first node I create a textbox, a datetimepicker and a combobox
When I click on the next node I create a datetimepicker, and two combobox.
etc...
The problem is that when the user will press a button I want to take the values from these controls and use them to create a report.
What I tried is to get the type
For Each cnt As Control In pn.Controls
l1.Items.Add(cnt.GetType)
Next
but how I can get the value, the text, or the selectedvalue.
Each control is different
I have crashed my head to the wall
6 Replies - 1147 Views - Last Post: 22 March 2012 - 06:00 AM
#1
Take the values of a variety of controls in a panel
Posted 20 March 2012 - 07:49 AM
Replies To: Take the values of a variety of controls in a panel
#2
Re: Take the values of a variety of controls in a panel
Posted 20 March 2012 - 08:31 AM
Using the property text I was able to take the values but a strings
I would like to have the in their original type (as integer or as date)
I would like to have the in their original type (as integer or as date)
#3
Re: Take the values of a variety of controls in a panel
Posted 20 March 2012 - 08:38 AM
You try something like this have a look and see what you think.
Dim ctrl As Control
For Each ctrl In container.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
Dim txt As TextBox = CType(ctrl, TextBox)
txt.Text = ""
End If
If (ctrl.GetType() Is GetType(CheckBox)) Then
Dim chkbx As CheckBox = CType(ctrl, CheckBox)
chkbx.Checked = False
End If
If (ctrl.GetType() Is GetType(ComboBox)) Then
Dim cbobx As ComboBox = CType(ctrl, ComboBox)
cbobx.SelectedIndex = -1
End If
If (ctrl.GetType() Is GetType(DateTimePicker)) Then
Dim dtp As DateTimePicker = CType(ctrl, DateTimePicker)
dtp.Value = Now()
End If
Next
This post has been edited by m_wylie85: 20 March 2012 - 08:42 AM
#4
Re: Take the values of a variety of controls in a panel
Posted 20 March 2012 - 08:46 AM
Thank you very much m_wylie85.
I tried that, but the thing with this solution is that you set the values.
I want to get the values
I tried that, but the thing with this solution is that you set the values.
I want to get the values
#5
Re: Take the values of a variety of controls in a panel
Posted 20 March 2012 - 10:49 AM
Yeah i know but that it's just to point you in the right direction edit it to suit you needs. If you have problem editing let me know i will try to help but i would like you to try to edit this first. Do some research on google and msdn read up on how to loop through controls and so on
#6
Re: Take the values of a variety of controls in a panel
Posted 20 March 2012 - 12:26 PM
You may think about making a UserControl and load the group of controls you need there. This exposes them via the UC. You then expose a property like the datatable for populating the controls which you set when you create the UC.
#7
Re: Take the values of a variety of controls in a panel
Posted 22 March 2012 - 06:00 AM
WTF
The solution was in front of me.Actually the only problem was with combobox and to pull his value
I have built a function as follows
Thanks everyone for the help
The solution was in front of me.Actually the only problem was with combobox and to pull his value
I have built a function as follows
Public Function saveFilterParams(ByVal filterContainer As C1SplitContainer) As String()
Dim myList As New List(Of String)
For Each pn As C1SplitterPanel In filterContainer.Panels
For Each cnt As Control In pn.Controls
If cnt.GetType Is GetType(DateTimePicker) Then
Dim dtpTemp As New DateTimePicker
dtpTemp.Value = cnt.Text
myList.Add(dtpTemp.Value)
ElseIf cnt.GetType Is GetType(ComboBox) Then
Dim cbTemp As ComboBox = CType(cnt, ComboBox)
Dim cbTemp As ComboBox = CType(cnt, ComboBox)
myList.Add(cbTemp.SelectedValue)
ElseIf cnt.GetType Is GetType(TextBox) Then
myList.Add(cnt.Text)
End If
Next
Next
saveFilterParams = myList.ToArray
End Function
Thanks everyone for the help
This post has been edited by macosxnerd101: 22 March 2012 - 06:44 AM
Reason for edit:: Please use code tags
Page 1 of 1

New Topic/Question
Reply


MultiQuote



|