UserControl + ArrayList + vb.net - vb.net

When i get the text of a listbox i write
ListBox1.Items(2).ToString()
What is the code that allows me to do this?
UserControl.positioniwant(2).title
UserControl.positioniwant(1).msg

It's called an "Indexed Property":
Public Class Foo
Public Property Position(ByVal index As Integer) As String
Get
Return _position(index)
End Get
Set(ByVal Value As String)
_position(index) = Value
End Set
End Property
Private _position(9) As String
End Class

Related

Combine two tables into one entity framework? (SQLite)

I am using the EntityFramework.SQLite library and for the life of me can not figure out how to combine two tables together into a temporary table for display purposes in xaml code.
Here's the code for my two tables I want to combine which is about all I am using right now besides a class for my temp table called CategoryList (this is part of the business/data logic dll library):
Partial Public Class CategoryList
Public Sub New()
Me.CategoryInfo = New CategoryReference
'Me.CategoryCode = New HashSet(Of CategoryCodes)
Me.CategoryCodes = New CategoryCodes
End Sub
Public Property MyId As Integer
<Key, ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
<Key, ForeignKey("CategoryID")>
Public CategoryID As Integer
'Public Property CategoryCode As ICollection(Of CategoryCodes)
Public Property CategoryInfo As CategoryReference
' Public Property CategoryInfo As ICollection(Of CategoryReference)
Public Property CategoryCodes As CategoryCodes
End Class
<Table("CategoryCodes")>
Public Class CategoryCodes 'category shortnames/codes
<MaxLength(100)>
<Required>
Public Property CategoryCode As String
Get
Return _CategoryCode
End Get
Set(value As String)
_CategoryCode = value
End Set
End Property
Private _CategoryCode As String
'<NotNull>
' <PrimaryKey>
'<Unique(Name:="UQ__CategoryCodes__0000000000000081_CategoryCodes", Order:=0)>
<Key>
<Required>
Public Property CodeID As Integer
Get
Return CategoryCode
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
End Class
<Table("CategoryReference")>
Partial Public Class CategoryReference 'table design for category data
<MaxLength(100)>
Public Property CategoryName As String
Get
Return _CategoryName
End Get
Set(value As String)
_CategoryName = value
End Set
End Property
Private _CategoryName As String
<MaxLength(100)>
Public Property CategoryDescription As String
Get
Return _CategoryDescription
End Get
Set(value As String)
_CategoryDescription = value
End Set
End Property
Private _CategoryDescription As String
'<Unique(Name:="UQ__CatagoryReference__000000000000005F_CatagoryReference", Order:=0)>
<ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
Get
Return _CodeID
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
'<Unique(Name:="UQ__CatagoryReference__000000000000005A_CatagoryReference", Order:=0)>
<Key>
<Required>
Public Property CategoryID As Integer
Get
Return _CategoryID
End Get
Set(value As Integer)
_CategoryID = value
End Set
End Property
Private _CategoryID As Integer
End Class
It may seem long but the tables are very simple and the get/set blocks make it look long (A vb.net editor can turn them into simple property's if she/he wishes). I may be using the CategoryList class wrong but here's where I use it in my xaml datasource in my main application code (I have business logic/data processing in a dll library):
Private Property ViewModel As List(Of UIELLUWP.DataAccess.CategoryList)
Dim categories As New UIELLUWP.DataAccess.SQLiteDb
ViewModel = categories.Categories.ToList
Errors received with current code:
I receive an error that Table "CategoryList" does not exist when I run the above code.
my solution I found out to this question was to add asnotracking because tracking was taking place.

In vb.net, defining a dictionary type in a class

New to using a Dictionary list.
I have an api that is returning a "task object" defined as:
id As Integer
options As Dictionary(string, string)
So I am defining a class called Task to store the returned "task object".
Public Class Task
Private _id As Integer
Public Property Id() As Integer
Get
Return _id
End Get
Set(value As Integer
_id = value
End Set
End Property
Private _optionlist As New List(Of Option)
Public Property OptionList() As List(Of Option)
Get
Return _optionlist
End Get
Set(ByVal value As List(Of Option))
_optionlist = value
End Set
End Property
End Class
Public Class Option
Private _key As String
Public Property Key() As String
Get
Return _key
End Get
Set(value As String)
_key = value
End Set
End Property
Private _value As String
Public Property Value() As String
Get
Return _value
End Get
Set(value As String)
_value = value
End Set
End Property
End Class
I will assign the "task object" returned from the api to this Task class.
I defined options as a list. Is that correct?
I will also have to read the option in my class and later repopulate it to send back to the api via function call.
Could use some help...thanks.
You can add the property to the class directly:
Public Class Task
Private _id As Integer
Private options As Dictionary(of string, string)
You can also create Get and Set methods for the "options" parameter.

Declare and and define Property in VB

I have two Class and I want to save my data into arrays form text box like this:
Students.Name(txtID.Text-1).MathMark = txtMark.Text
but I get error: Object reference not set to an instance of an object
my code is:
Dim StudentsNumber as Integer = txtstdnum.Text
Dim Students as New StudentsInf(StudentsNumber)
Students.Name(txtID.Text-1).MathMark = txtMark.Text
Public Class StudentsInf
Private mName() As String
Sub New(ByVal StudentNumbers As Integer)
ReDim mName(StudentNumbers-1)
End Sub
Public Property Name(ByVal Index As Integer) As LessonsMark
Get
Return mName(Index)
End Get
Set(ByVal Value As LessonsMark)
mName(Index) = Value
End Set
End Property
End Class
Public Class LessonsMark
Private mMathMark() As Object
Public Property MathMark() As Object
Get
Return mMathMark
End Get
Set(ByVal Value As Object)
mMathMark = Value
End Set
End Property
End Class
This:
Private mName() As String
needs to be:
Private mName() As LessonsMark
then you have to create the objects in your constructor, something like:
Sub New(ByVal StudentNumbers As Integer)
ReDim mName(StudentNumbers - 1)
For i As Integer = 0 To StudentNumbers - 1
mName(i) = New LessonsMark()
Next
End Sub
then it looks like your LessonsMark class is declaring an array of objects when it looks like it should be just a string property:
Public Class LessonsMark
Private mMathMark As String
Public Property MathMark As String
Get
Return mMathMark
End Get
Set(ByVal Value As String)
mMathMark = Value
End Set
End Property
End Class

Storing a value for each ComboBox item

In lack of a Value property I planned to use Classes for storing Text and Value properties for my ComboBox items. So far I've succeeded.
Here is my class:
Public Class clCombobox
Public cname As String
Public cvalue As Integer
Public Property Display() As String
Get
Return Me.cname
End Get
Set(ByVal value As String)
Me.cname = value
End Set
End Property
Public Property Value() As String
Get
Return Me.cvalue
End Get
Set(ByVal value As String)
Me.cvalue = value
End Set
End Property
Public Sub New(ByVal name As String, ByVal value As String)
cname = name
cvalue = value
End Sub
Public Overrides Function ToString() As String
Return cname
End Function
End Class
Data is being added to the ComboBox like this:
cmbComboxBox.Items.Add(New clCombobox("Text", 1))
It seems like this works so far. But how do I get data back. Like if I want the value of the selected CheckBox item?
I tried using:
CType(cmbCombobox.SelectedItem, clCombobox).Value()
Did not work.
As per the documentation, use the SelectedItem property to retrieve the object that you stored in it.
Code to retrieve value you want:
Dim selectedItem as clCombobox = CType(cmbComboBox.SelectedItem, clCombobox)
Dim value As Integer = selectedItem.cvalue

OData made from objects

Lets say I have a class called "Item" and "SubItems"
Public Class SubItem
Private _SubItemName As String
Public Property SubItemName() As String
Get
Return _SubItemName
End Get
Set(ByVal value As String)
_SubItemName = value
End Set
End Property
End Class
<DataServiceKey("Name")> _
Public Class Item
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _SubItems As List(Of SubItem)
Public Property SubItems() As List(Of SubItem)
Get
Return _SubItems
End Get
Set(ByVal value As List(Of SubItem))
_SubItems = value
End Set
End Property
End Class
How would I create a service that would return a list of Items and upon looking up an individual item I would be able to see the sub items.
You can check out WCF Data Servies reflection provider, e.g.,
http://blogs.msdn.com/b/alexj/archive/2010/06/11/tip-56-writing-an-odata-service-using-the-reflection-provider.aspx
http://msdn.microsoft.com/en-us/library/dd728281.aspx
Hope this helps.