Finding UserControl in FlowLayoutPanel - vb.net

Good afternoon!
The form has a FlowLayoutPanel with a list of users (created in UserControl)
A UserControl is added to the FlowLayoutPanel with data taken from the json file.
How can I search for the UserName tag through a text field by hiding the elements.
For example, I enter "Ben", all elements in the FlowLayoutPanel that do not match the request are hidden. Only those with "Ben" in the UserName remain
UserControl Code:
Imports System.ComponentModel
Partial Public Class CustomListItem
Inherits UserControl
Private _UserName As String
Private _ID As Integer
Private _Login As String
Private _Title As String
Private _Dep As String
Private _Mail As String
Private _Phone As String
Private _Picture As Image
<Category("Custom Props")>
Public Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal value As String)
_UserName = value
Lbl_UserName.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property ID() As Integer
Get
Return _ID
End Get
Set(ByVal value As Integer)
_ID = value
Lbl_ID.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Login() As String
Get
Return _Login
End Get
Set(ByVal value As String)
_Login = value
Lbl_Login.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
Lbl_Title.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Dep() As String
Get
Return _Dep
End Get
Set(ByVal value As String)
_Dep = value
Lbl_Dep.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Phone() As String
Get
Return _Phone
End Get
Set(ByVal value As String)
_Phone = value
Lbl_Phone.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Mail() As String
Get
Return _Mail
End Get
Set(ByVal value As String)
_Mail = value
Lbl_Mail.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Picture() As Image
Get
Return _Picture
End Get
Set(ByVal value As Image)
_Picture = value
pic_img.Image = value
End Set
End Property
Private Sub CustomListItem_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave
BackColor = Color.White
End Sub
Private Sub CustomListItem_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
BackColor = Color.Silver
End Sub
End Class
Form code:
Imports System.IO
Imports Newtonsoft.Json
Public Class Form1
Public listUser As List(Of UserList)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
listUser = New List(Of UserList)()
Dim json = File.ReadAllText("D:\Users.json")
listUser = JsonConvert.DeserializeObject(Of List(Of UserList))(json)
Dim listItems = New CustomListItem(29) {}
FlowLayoutPanel1.Controls.Clear()
Dim i As Integer = 0
For Each UserList In listUser.Take(30)
listItems(i) = New CustomListItem With {
.ID = UserList.Id,
.UserName = UserList.UserName,
.Login = UserList.Login,
.Title = UserList.Title,
.Dep = UserList.Dep,
.Mail = UserList.Mail,
.Phone = UserList.Phone,
.Picture = My.Resources.User128
}
FlowLayoutPanel1.Controls.Add(listItems(i))
i += 1
Next UserList
End Sub
End Class
Public Class UserList
Public Property Id() As Integer
Public Property UserName() As String
Public Property Login() As String
Public Property Title() As String
Public Property Dep() As String
Public Property Mail() As String
Public Property Phone() As String
End Class
Another request to clarify the moment what these lines mean (and specifically the numbers in them)
Dim listItems = New CustomListItem(29) {}
...
For Each UserList In listUser.Take(30)
As I understand, this is the number of UserControls created in the FlowLayoutPanel. But my number of entries in the json file may be different, not known to me. And it will not be possible to count each time the entries in the json file. Tell me, how can I get away from the specific number of UserControls created in the FlowLayoutPanel?
Thank you in advance for your answers and comments. Have a good day!
And of course the JSON file itself:
[
{
"id":"1",
"UserName":"Fred Smith",
"Login":"f.smith",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"f.smith#domain.com",
"Phone":"111",
},
{
"id":"2",
"UserName":"Ben Taylor",
"Login":"b.taylor",
"Title":"programmer",
"Dep":"IT infrastcomcture",
"Mail":"b.taylor#domain.com",
"Phone":"100",
},
{
"id":"3",
"UserName":"Steve Harris",
"Login":"s.harris",
"Title":"System Administrator",
"Dep":"IT infrastcomcture",
"Mail":"s.harris#domain.com",
"Phone":"263",
},
{
"id":"4",
"UserName":"Tom Walker",
"Login":"t.walker",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"t.walker#domain.com",
"Phone":"263",
},
{
"id":"5",
"UserName":"Tom Davis",
"Login":"t.davis",
"Title":"engineer",
"Dep":"IT infrastcomcture",
"Mail":"t.davis#domain.com",
"Phone":"200",
},
{
"id":"6",
"UserName":"Ben Walker",
"Login":"b.walker",
"Title":"System Administrator",
"Dep":"IT infrastcomcture",
"Mail":"b.walker#domain.com",
"Phone":"167",
},
]

Assuming that every control in your FlowLayoutPanel is the same type:
For Each cli As CustomListItem In FlowLayoutPanel1.Controls
cli.Visible = (cli.UserName = filterValue)
Next
Each user control will be visible if and only if its UserName property is equal to the specified value.

Related

lists on custom listview are all the same, should be different in Visual Basic

How to display a list on a custom listview that varies like this :
true
Not like this:
false
where to see each other, everything is the same?
I created Daftar.vb using User Controls (Windows Forms) and I created a custom list view using FlowLayoutPanel and in it I entered the Daftar Toolbox
code :
Daftar.vb
Imports System.ComponentModel
Public Class Daftar1
#Region "Properties"
Private _title As String
Private _message As String
Private _icon As Image
<Category("Custom Props")>
Public Property Title As String
Get
Return _title
End Get
Set(ByVal value As String)
_title = value
judul.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Message As String
Get
Return _message
End Get
Set(ByVal value As String)
_message = value
deskripsi.Text = value
End Set
End Property
<Category("Custom Props")>
Public Property Icon As Image
Get
Return _icon
End Get
Set(ByVal value As Image)
_icon = value
gambar.Image = value
End Set
End Property
#End Region
End Class
RestaurantApp.vb
Public Class RestaurantApp
Private Sub PopulateItems()
Dim listItems As Daftar1() = New Daftar1(20) {}
Dim i As Integer
For i = 0 To listItems.Length - 1
listItems(i) = New Daftar1()
listItems(i).Title = "vdsvhd"
listItems(i).Message = "Penjelasan"
If i <> 0 Then
panelDaftar.Controls.Add(listItems(i))
End If
Next
End Sub
Private Sub RestaurantApp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call Me.PopulateItems()
End Sub
End Class
After I search on Stackoverflow and Youtube, I've managed to find the answer. The following is the code for RestaurantApp.vb :
Public Class RestaurantApp
Private Sub PopulateItems()
Dim listItems As Daftar1() = New Daftar1(5) {}
Dim judul As String() = New String(4) {"Burger", "Sosis", "Nasi", "Pizza", "Ayam"}
Dim penjelasan As String() = New String(4) {"a", "b", "c", "d", "e"}
Dim i As Integer
For i = 0 To listItems.Length - 1
If i < judul.Length And i < penjelasan.Length Then
listItems(i) = New Daftar1()
listItems(i).Title = judul(i)
listItems(i).Message = penjelasan(i)
If i <> 0 Then
panelDaftar.Controls.Add(listItems(i))
End If
End If
Next
End Sub
Private Sub RestaurantApp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call Me.PopulateItems()
End Sub
End Class
Thank you #anu6is and Stackoverflow

Deserialize json string into visual basic object using Newtonsoft.Json.JsonConvert.DeserializeObject VISUAL BASIC

I'm using Newtonsoft.Json.JsonConvert.DeserializeObject VISUAL BASIC, and i need to deserialize the json string into a object called 'Elemento'.
My code:
request.RequestFormat = DataFormat.Json
Dim json As String = "{""where"":""id==" + oid + """, ""selects"":[""current"", ""name"", ""type"", ""revision"", ""owner"", ""description""]}"
request.AddParameter("application/json", json, ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
Dim code As String = response.StatusCode
Dim elemento As Elemento = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Elemento)(response.Content)
Dim tipo As String = elemento.type
Dim current As String = elemento.current
Dim nombre As String = elemento.name
Return elemento
The recibed json:
{
"msg": "OK",
"data": [
{
"name": "LABORATORIO",
"owner": "aviteri",
"current": "Active",
"id": "62676.39210.18680.50051",
"type": "Workspace",
"revision": "0000000026"
}
],
"objectsLabels": {
"name": "Name",
"owner": "Owner",
"current": "Maturity State",
"id": "emxFramework.Attribute.id",
"type": "Type",
"revision": "Revision"
}
}
I need to deserialize the 'data' info of the json into my object Elemento, i tried the last code but i am receiving empty information. Just ignore the objectsLabels data.
This is my 'Elemento' class, it has the same properties and few more:
Public Class Elemento
#Region "Variables"
Public Enum Valores
Nulo
ParaInformacion
Rechazado
RevisadoConComentarios
RevisadoSinComentarios
End Enum
Public Enum Estado
Privado
En_Desarrollo
Emitido
Completado
Emitido_Cliente
Obsoleto
Active
Create
End Enum
End Enum
Private _objectID As String
Private _name As String
Private _typeName As String
Private _description As String
Private _owner As String
Private _revision As String
Private _title As String
Private _originated As String
Private _modified As String
Private _estado As Estado
Private _current As String
#End Region
#Region "Properties"
Public Property id() As String
Get
Return _objectID
End Get
Set(ByVal value As String)
_objectID = value
End Set
End Property
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property type() As String
Get
Return _typeName
End Get
Set(ByVal value As String)
_typeName = value
End Set
End Property
Public Property description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property
Public Property owner() As String
Get
Return _owner
End Get
Set(ByVal value As String)
_owner = value
End Set
End Property
Public Property revision() As String
Get
Return _revision
End Get
Set(ByVal value As String)
_revision = value
End Set
End Property
Public Property title() As String
Get
Return _title
End Get
Set(ByVal value As String)
_title = value
End Set
End Property
Public Property originated() As String
Get
Return _originated
End Get
Set(ByVal value As String)
_originated = value
End Set
End Property
Public Property modified() As String
Get
Return _modified
End Get
Set(ByVal value As String)
_modified = value
End Set
End Property
Public Property current() As String
Get
Return _estado
End Get
Set(ByVal value As String)
_estado = CType([Enum].Parse(GetType(Estado), value), Estado)
End Set
End Property
#End Region
As Jimi said in the comments, i was missing the RootObject, a class with the msg data and objectsLabels properties.
I have created a class called ResponseListElements
Public Class ResponseListElements
#Region "Variables"
Private _msg As String = String.Empty
Private _data As List(Of Elemento)
#End Region
#Region "Properties"
Public Property msg() As String
Get
Return _msg
End Get
Set(ByVal value As String)
_msg = value
End Set
End Property
Public Property data() As List(Of Elemento)
Get
Return _data
End Get
Set(ByVal value As List(Of Elemento))
_data = value
End Set
End Property
#End Region
End Class
And them i changed this line:
Dim elemento As Elemento = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Elemento)(response.Content)
By this one:
Dim elemento As ResponseListElements = Newtonsoft.Json.JsonConvert.DeserializeObject(Of ResponseListElements)(response.Content)

List.Add(var) overwrites previous items in list

Every time when you press the button, you should get a customer added to your list. But it just overrides my previous value and doesn't update the List.
This is exactly what they did in my book, but I don't know why the next variable doesn't get added to the list
Private Sub btnOpslaan_Click(sender As Object, e As EventArgs) Handles btnOpslaan.Click
Dim klantenlijst As New List(Of Klant)
Dim nieuwe_klant As New Klant
Dim path As String = IO.Path.GetTempFileName()
nieuwe_klant.Naam = txtNaam.Text
nieuwe_klant.Straat = txtStraat.Text
nieuwe_klant.Postcode = txtPostcode.Text
nieuwe_klant.Gemeente = txtGemeente.Text
nieuwe_klant.Telefoon = txtTelefoon.Text
nieuwe_klant.Email = txtEmail.Text
If chkHardware.Checked = True Then
nieuwe_klant.Hardware = True
End If
If chkInternet.Checked = True Then
nieuwe_klant.Internet = True
End If
If chkMultimedia.Checked = True Then
nieuwe_klant.Multimedia = True
End If
If chkSoftware.Checked = True Then
nieuwe_klant.Software = True
End If
klantenlijst.Add(nieuwe_klant)
MsgBox(klantenlijst.Count)
End Sub
My class "Klant"
Public Class Klant
Private mNaam As String
Private mStraat As String
Private mPostcode As String
Private mGemeente As String
Private mTelefoon As String
Private mEmail As String
Private mHardware As Boolean
Private mSoftware As Boolean
Private mInternet As Boolean
Private mMultimedia As Boolean
Public Sub New()
mHardware = False
mInternet = False
mSoftware = False
mMultimedia = False
mNaam = "Niet ingevuld"
mStraat = "Niet ingevuld"
mPostcode = "Niet ingevuld"
mGemeente = "Niet ingevuld"
mTelefoon = "Niet ingevuld"
mEmail = "Niet ingevuld"
End Sub
Public Property Hardware() As Boolean
Get
Return mHardware
End Get
Set(ByVal value As Boolean)
mHardware = value
End Set
End Property
Public Property Software() As Boolean
Get
Return mSoftware
End Get
Set(ByVal value As Boolean)
mSoftware = value
End Set
End Property
Public Property Internet() As Boolean
Get
Return mInternet
End Get
Set(ByVal value As Boolean)
mInternet = value
End Set
End Property
Public Property Multimedia() As Boolean
Get
Return mMultimedia
End Get
Set(ByVal value As Boolean)
mMultimedia = value
End Set
End Property
Public Property Naam() As String
Get
Return mNaam
End Get
Set(ByVal value As String)
mNaam = value
End Set
End Property
Public Property Straat() As String
Get
Return mStraat
End Get
Set(ByVal value As String)
mStraat = value
End Set
End Property
Public Property Postcode() As String
Get
Return mPostcode
End Get
Set(ByVal value As String)
mPostcode = value
End Set
End Property
Public Property Gemeente() As String
Get
Return mGemeente
End Get
Set(ByVal value As String)
mGemeente = value
End Set
End Property
Public Property Telefoon() As String
Get
Return mTelefoon
End Get
Set(ByVal value As String)
mTelefoon = value
End Set
End Property
Public Property Email() As String
Get
Return mEmail
End Get
Set(ByVal value As String)
mEmail = value
End Set
End Property
End Class
The issue here is that on every click, you are declaring a new 'klantenlijst' and making it private. Just declare it outside of the click and you'll get the desired result:
Dim klantenlijst As New List(Of Klant)
Private Sub btnOpslaan_Click(sender As Object, e As EventArgs) Handles btnOpslaan.Click
Dim nieuwe_klant As New Klant
Dim path As String = IO.Path.GetTempFileName()
nieuwe_klant.Naam = txtNaam.Text
//continue your code...
klantenlijst.Add(nieuwe_klant)
MsgBox(klantenlijst.Count)
Every time the button is clicked, you create a new list:
Dim klantenlijst As New List(Of Klant)
And then you add exactly one item to that list:
klantenlijst.Add(nieuwe_klant)
So that list will only ever contain one item.
Instead, create a class-level list and add to that. So put this line at the class level:
Dim klantenlijst As New List(Of Klant)
Then the same list is available throughout the instance of the class. A few things to note:
Without more context, it's possible that you may even be looking for a larger scope than the class. There are a variety of places you can store information, a class-level variable is simply the next higher scope from your method-level variable.
If you're using ASP.NET then the lifespan of the class is very short (per request) and not persisted between requests. In that case you'd want to store your data somewhere else, possibly in session state or a database.

Saving Control Values to Class Object Property

I have this userform that I has a bunch of controls on it, and the control name corresponds to a property name that i have defined inside OrderPrompts.
When the user clicks on the save button, I am trying to save all those control values back to the original object OrderPrompts.
Here's the order prompts classs
Option Explicit
Private pSKU As String
Private pWidth As String
Private pHeight As String
Private pDepth As String
Private pLeftSwing As String
Private pRightSwing As String
Private pLeftFinishedEnd As String
Private pRightFinishedEnd As String
Private pToeKickHeight As String
Private pAdjShelfQty As String
Private pLeftStileWidth As String
Private pRightStileWidth As String
Private pTopRailWidth As String
Private pBottomRailWidth As String
Private pExtendLeftFFDown As String
Private pExtendLeftFFUp As String
Private pExtendRightFFDown As String
Private pExtendRightFFUp As String
Private pExtendTopRail As String
Private pExtendBottomRail As String
Private pBayHeightCalc As String
Private pBay1Height As String
Private pBay2Height As String
Private pBay3Height As String
Private pBay4Height As String
Private pBay5Height As String
Private pBayWidthCalc As String
Private pBay1Width As String
Private pBay2Width As String
Private pBay3Width As String
Private pBay4Width As String
Private pBay5Width As String
Private pDrawerFrontCalc As String
Private pTopDrawerFront As String
Private pSecondDrawerFront As String
Private pThirdDrawerFront As String
Private pBottomDrawerFront As String
Public Property Get SKU() As String
SKU = pSKU
End Property
Public Property Let SKU(Value As String)
pSKU = Value
End Property
Public Property Get Width() As String
Width = pWidth
End Property
Public Property Let Width(Value As String)
pWidth = Value
End Property
Public Property Get Height() As String
Height = pHeight
End Property
Public Property Let Height(Value As String)
pHeight = Value
End Property
Public Property Get Depth() As String
Depth = pDepth
End Property
Public Property Let Depth(Value As String)
pDepth = Value
End Property
Public Property Get LeftSwing() As String
LeftSwing = pLeftSwing
End Property
Public Property Let LeftSwing(Value As String)
pLeftSwing = Value
End Property
Public Property Get RightSwing() As String
RightSwing = pRightSwing
End Property
Public Property Let RightSwing(Value As String)
pRightSwing = Value
End Property
Public Property Get LeftFinishedEnd() As String
LeftFinishedEnd = pLeftFinishedEnd
End Property
Public Property Let LeftFinishedEnd(Value As String)
pLeftFinishedEnd = Value
End Property
Public Property Get RightFinishedEnd() As String
RightFinishedEnd = pRightFinishedEnd
End Property
Public Property Let RightFinishedEnd(Value As String)
pRightFinishedEnd = Value
End Property
Public Property Get ToeKickHeight() As String
ToeKickHeight = pToeKickHeight
End Property
Public Property Let ToeKickHeight(Value As String)
pToeKickHeight = Value
End Property
Public Property Get AdjShelfQty() As String
AdjShelfQty = pAdjShelfQty
End Property
Public Property Let AdjShelfQty(Value As String)
pAdjShelfQty = Value
End Property
Public Property Get LeftStileWidth() As String
LeftStileWidth = pLeftStileWidth
End Property
Public Property Let LeftStileWidth(Value As String)
pLeftStileWidth = Value
End Property
Public Property Get RightStileWidth() As String
RightStileWidth = pRightStileWidth
End Property
Public Property Let RightStileWidth(Value As String)
pRightStileWidth = Value
End Property
Public Property Get TopRailWidth() As String
TopRailWidth = pTopRailWidth
End Property
Public Property Let TopRailWidth(Value As String)
pTopRailWidth = Value
End Property
Public Property Get BottomRailWidth() As String
BottomRailWidth = pBottomRailWidth
End Property
Public Property Let BottomRailWidth(Value As String)
pBottomRailWidth = Value
End Property
Public Property Get ExtendLeftFFDown() As String
ExtendLeftFFDown = pExtendLeftFFDown
End Property
Public Property Let ExtendLeftFFDown(Value As String)
pExtendLeftFFDown = Value
End Property
Public Property Get ExtendLeftFFUp() As String
ExtendLeftFFUp = pExtendLeftFFUp
End Property
Public Property Let ExtendLeftFFUp(Value As String)
pExtendLeftFFUp = Value
End Property
Public Property Get ExtendRightFFDown() As String
ExtendRightFFDown = pExtendRightFFDown
End Property
Public Property Let ExtendRightFFDown(Value As String)
pExtendRightFFDown = Value
End Property
Public Property Get ExtendRightFFUp() As String
ExtendRightFFUp = pExtendRightFFUp
End Property
Public Property Let ExtendRightFFUp(Value As String)
pExtendRightFFUp = Value
End Property
Public Property Get ExtendTopRail() As String
ExtendTopRail = pExtendTopRail
End Property
Public Property Let ExtendTopRail(Value As String)
pExtendTopRail = Value
End Property
Public Property Get ExtendBottomRail() As String
ExtendBottomRail = pExtendBottomRail
End Property
Public Property Let ExtendBottomRail(Value As String)
pExtendBottomRail = Value
End Property
Public Property Get BayHeightCalc() As String
BayHeightCalc = pBayHeightCalc
End Property
Public Property Let BayHeightCalc(Value As String)
pBayHeightCalc = Value
End Property
Public Property Get Bay1Height() As String
Bay1Height = pBay1Height
End Property
Public Property Let Bay1Height(Value As String)
pBay1Height = Value
End Property
Public Property Get Bay2Height() As String
Bay2Height = pBay2Height
End Property
Public Property Let Bay2Height(Value As String)
pBay2Height = Value
End Property
Public Property Get Bay3Height() As String
Bay3Height = pBay3Height
End Property
Public Property Let Bay3Height(Value As String)
pBay3Height = Value
End Property
Public Property Get Bay4Height() As String
Bay4Height = pBay4Height
End Property
Public Property Let Bay4Height(Value As String)
pBay4Height = Value
End Property
Public Property Get Bay5Height() As String
Bay5Height = pBay5Height
End Property
Public Property Let Bay5Height(Value As String)
pBay5Height = Value
End Property
Public Property Get BayWidthCalc() As String
BayWidthCalc = pBayWidthCalc
End Property
Public Property Let BayWidthCalc(Value As String)
pBayWidthCalc = Value
End Property
Public Property Get Bay1Width() As String
Bay1Width = pBay1Width
End Property
Public Property Let Bay1Width(Value As String)
pBay1Width = Value
End Property
Public Property Get Bay2Width() As String
Bay2Width = pBay2Width
End Property
Public Property Let Bay2Width(Value As String)
pBay2Width = Value
End Property
Public Property Get Bay3Width() As String
Bay3Width = pBay3Width
End Property
Public Property Let Bay3Width(Value As String)
pBay3Width = Value
End Property
Public Property Get Bay4Width() As String
Bay4Width = pBay4Width
End Property
Public Property Let Bay4Width(Value As String)
pBay4Width = Value
End Property
Public Property Get Bay5Width() As String
Bay5Width = pBay5Width
End Property
Public Property Let Bay5Width(Value As String)
pBay5Width = Value
End Property
Public Property Get DrawerFrontCalc() As String
DrawerFrontCalc = pDrawerFrontCalc
End Property
Public Property Let DrawerFrontCalc(Value As String)
pDrawerFrontCalc = Value
End Property
Public Property Get TopDrawerFront() As String
TopDrawerFront = pTopDrawerFront
End Property
Public Property Let TopDrawerFront(Value As String)
pTopDrawerFront = Value
End Property
Public Property Get SecondDrawerFront() As String
SecondDrawerFront = pSecondDrawerFront
End Property
Public Property Let SecondDrawerFront(Value As String)
pSecondDrawerFront = Value
End Property
Public Property Get ThirdDrawerFront() As String
ThirdDrawerFront = pThirdDrawerFront
End Property
Public Property Let ThirdDrawerFront(Value As String)
pThirdDrawerFront = Value
End Property
Public Property Get BottomDrawerFront() As String
BottomDrawerFront = pBottomDrawerFront
End Property
Public Property Let BottomDrawerFront(Value As String)
pBottomDrawerFront = Value
End Property
Here's how OrderPrompts is defined inside the form control
Public Property Get OrderPrompts() As clsOrderPromptRow
Set OrderPrompts = pOrderPrompts
End Property
Public Property Let OrderPrompts(Value As clsOrderPromptRow)
Set pOrderPrompts = Value
End Property
Here's the code I have for the button click
Private Sub btnSave_Click()
Dim Prompt As Control
Dim PageIndex As Long
For PageIndex = 0 To Me.TabControl.Pages.Count - 1
For Each Prompt In TabControl.Pages(PageIndex).Controls
'MsgBox (TypeName(Prompt))
'CallByName(Me.ProductPromptMapping, PromptControl.ControlName, VbGet)
Select Case TypeName(Prompt)
Case "TextBox"
CallByName Me.OrderPrompts, Prompt.Name, VbLet, Prompt.Text
Case "OptionButton"
CallByName Me.OrderPrompts, Prompt.Name, VbLet, Prompt.ControlFormat.Value
Case "CheckBox"
CallByName Me.OrderPrompts, Prompt.Name, VbLet, CStr(Prompt.Value)
Case "ComboBox"
CallByName Me.OrderPrompts, Prompt.Name, VbLet, Prompt.Value
End Select
Next
Next
MsgBox (OrderPrompts.Width)
Me.Hide
End Sub
The problem i am having is with saving the Checkbox, Combobox, and OptionButton values back to the object. The textbox value works just fine. So I am not sure what to fix. I keep getting either a type mismatch error or null not supported.
Any help is appreciated. Thanks in advance.
The short answer is to use Prompt.Object.Value for all the controls.
Public Sub PrintControls()
Dim Prompt As Control
Dim PageIndex As Long
For PageIndex = 0 To Me.TabControl.Pages.Count - 1
For Each Prompt In TabControl.Pages(PageIndex).Controls
Debug.Print "Name:", Prompt.Name, "Value:", Prompt.Object.Value
Next
Next
End Sub
I really liked your concept so I wrote my own class to Save and Load control values. My class saves references to the controls and their values for easy retrieval. Download Workbook
When the Save button is clicked a reference to each control on the MultiPage is saved into a Scripting Dictionary. The Dictionary is then added to an ArrayList and the Dictionary's index in the ArrayList is added to a ListBox. When the ListBox is clicked the current settings are saved and the previous settings, corresponding to the Listbox's Value, are loaded.
Class: SettingsDictionaryClass
Option Explicit
Private ControlSetting As Object
Private mTabControl As MSForms.MultiPage
Sub Init(TabControl As MSForms.MultiPage)
Set mTabControl = TabControl
Set ControlSetting = CreateObject("System.Collections.ArrayList")
End Sub
Function Save() As Long
Dim subDict As Object: Set subDict = CreateObject("Scripting.Dictionary")
Dim ctrl As MSForms.Control
Dim PageIndex As Long
With mTabControl
For PageIndex = 0 To .Pages.Count - 1
For Each ctrl In .Pages(PageIndex).Controls
subDict.Add ctrl, ctrl.Object.Value
Next
Next
End With
Save = ControlSetting.Count
ControlSetting.Add subDict
End Function
Sub LoadValues(ListIndex As Long, Optional SaveCurrent As Boolean)
Dim ctrl
Dim Settings As Object
If SaveSetting Then Save
Set Settings = ControlSetting.Item(ListIndex)
For Each ctrl In Settings
ctrl.Value = Settings(ctrl)
Next
End Sub
Userform: Userform1
Option Explicit
Private SettingsDictionary As SettingsDictionaryClass
Private Sub btnSave_Click()
lboSettings.AddItem SettingsDictionary.Save
End Sub
Private Sub lboSettings_Click()
SettingsDictionary.LoadValues lboSettings.Value, True
End Sub
Private Sub UserForm_Initialize()
Set SettingsDictionary = New SettingsDictionaryClass
SettingsDictionary.Init TabControl
End Sub

How to add datas from one class to another

I have a problem and i don't know how to solve it.
I have 2 different classs, and i need to get a datas that are in fist class to another class.
My first class look like :
Public Class ZnrEk1Ospos
Private _sif_tvrtka As Integer
Private _sif_radnika As Integer
Private _red_broj As Integer
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Private _funkcija As String
Private _status_obrasca As Integer
Private _glavni_instruktor As Integer
Private _instruktor_prezime As String
Private _instruktor_sprema As String
Private _instruktor_funkcija As String
Private _evidencijski_broj As String
Private _potvrda As String
Public Sub New()
'Do nothing as all private variables has been initiated
End Sub
Public Sub New(ByVal DataRow As DataRow)
_sif_tvrtka = CInt(DataRow.Item("sif_tvrtka"))
_sif_radnika = CInt(DataRow.Item("sif_radnika"))
_red_broj = CInt(DataRow.Item("red_broj"))
_sif_ovl_osobe = CInt(DataRow.Item("sif_ovl_osobe"))
_datum_teorija = IIf(IsDBNull(DataRow.Item("datum_teorija")), Nothing, DataRow.Item("datum_teorija"))
_datum_praksa = IIf(IsDBNull(DataRow.Item("datum_praksa")), Nothing, DataRow.Item("datum_praksa"))
_prezime_ime = IIf(IsDBNull(DataRow.Item("prezime_ime")), "", Trim(DataRow.Item("prezime_ime")))
_strucna_sprema = IIf(IsDBNull(DataRow.Item("strucna_sprema")), "", Trim(DataRow.Item("strucna_sprema")))
_funkcija = IIf(IsDBNull(DataRow.Item("funkcija")), "", Trim(DataRow.Item("funkcija")))
_status_obrasca = CInt(DataRow.Item("status_obrasca"))
_glavni_instruktor = CInt(DataRow.Item("glavni_instruktor"))
_instruktor_prezime = IIf(IsDBNull(DataRow.Item("instruktor_prezime")), "", Trim(DataRow.Item("instruktor_prezime")))
_instruktor_sprema = IIf(IsDBNull(DataRow.Item("instruktor_sprema")), "", Trim(DataRow.Item("instruktor_sprema")))
_instruktor_funkcija = IIf(IsDBNull(DataRow.Item("instruktor_funkcija")), "", Trim(DataRow.Item("instruktor_funkcija")))
_evidencijski_broj = IIf(IsDBNull(DataRow.Item("evidencijski_broj")), "", Trim(DataRow.Item("evidencijski_broj")))
_potvrda = IIf(IsDBNull(DataRow.Item("potvrda")), "", Trim(DataRow.Item("potvrda").ToString))
End Sub
Public Property sif_tvrtka() As Integer
Get
Return _sif_tvrtka
End Get
Set(ByVal value As Integer)
_sif_tvrtka = value
End Set
End Property
Public Property sif_radnika() As Integer
Get
Return _sif_radnika
End Get
Set(ByVal value As Integer)
_sif_radnika = value
End Set
End Property
Public Property red_broj() As Integer
Get
Return _red_broj
End Get
Set(ByVal value As Integer)
_red_broj = value
End Set
End Property
Public Property sif_ovl_osobe() As Integer
Get
Return _sif_ovl_osobe
End Get
Set(ByVal value As Integer)
_sif_ovl_osobe = value
End Set
End Property
Public Property datum_teorija() As Date
Get
Return _datum_teorija
End Get
Set(ByVal value As Date)
_datum_teorija = value
End Set
End Property
Public Property datum_praksa() As Date
Get
Return _datum_praksa
End Get
Set(ByVal value As Date)
_datum_praksa = value
End Set
End Property
Public Property prezime_ime() As String
Get
Return _prezime_ime
End Get
Set(ByVal value As String)
_prezime_ime = value
End Set
End Property
Public Property strucna_sprema() As String
Get
Return _strucna_sprema
End Get
Set(ByVal value As String)
_strucna_sprema = value
End Set
End Property
Public Property funkcija() As String
Get
Return _funkcija
End Get
Set(ByVal value As String)
_funkcija = value
End Set
End Property
Public Property status_obrasca() As Integer
Get
Return _status_obrasca
End Get
Set(ByVal value As Integer)
_status_obrasca = value
End Set
End Property
Public Property glavni_instruktor() As Integer
Get
Return _glavni_instruktor
End Get
Set(ByVal value As Integer)
_glavni_instruktor = value
End Set
End Property
Public Property instruktor_prezime() As String
Get
Return _instruktor_prezime
End Get
Set(ByVal value As String)
_instruktor_prezime = value
End Set
End Property
Public Property instruktor_sprema() As String
Get
Return _instruktor_sprema
End Get
Set(ByVal value As String)
_instruktor_sprema = value
End Set
End Property
Public Property instruktor_funkcija() As String
Get
Return _instruktor_funkcija
End Get
Set(ByVal value As String)
_instruktor_funkcija = value
End Set
End Property
Public Property evidencijski_broj() As String
Get
Return _evidencijski_broj
End Get
Set(ByVal value As String)
_evidencijski_broj = value
End Set
End Property
Public Property potvrda() As String
Get
Return _potvrda
End Get
Set(ByVal value As String)
_potvrda = value
End Set
End Property
And my second class in wich i want go get data from my first class look like:
Public Class TempEK1OsposTeorija
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Now i need to get data in Public Class TempEK1OsposTeorija form class Public Class ZnrEk1Ospos.
Does anybody know how to do that?
You need to create a new instance of that class
Public Class TempEK1OsposTeorija
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Public sub PozoviKlasuIvratiPodatke()
' To use the word using you must implement the IDisposable Interface into first class
Using cl as new ZnrEk1Ospos
'get data from first class
_sif_ovl_osobe = cl._sif_ovl_osobe
_datum_teorija = cl._datum_teorija
_datum_praksa = cl._datum_praksa
_prezime_ime = cl._prezime_ime
_strucna_sprema = cl._strucna_sprema
End using
End sub
End class