VB.Net Create Extension As DataTable(Index) - vb.net

I have a question related with VB.Net Code.
I see that the DataTable we can use:
DataTable(0) ' This return a DataRow with the selected index
In the intellisense I see that this functionality can achieve with a extension... but, If I create a extension, always I need refer the Extension before to use it
Public Module asdadsdas
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)>
<System.Runtime.CompilerServices.ExtensionAttribute()>
Friend Function MyExt(ByVal pMyObject As MyObject, ByVal ColumnName As String) As MyObject.ColumnData
Return pMyObject.Columns(0)
End Function
End Module
Public Class MyObject
Friend Structure ColumnData
Friend vNombre As String
Friend vApellido As String
Friend vTelefono As String
Public Property Nombre As String
Get
Return Me.vNombre
End Get
Set(ByVal value As String)
Me.vNombre = value
End Set
End Property
End Structure
Friend Columns() As ColumnData
Public Sub add(ByVal MyColumn As String)
ReDim Columns(0)
Columns(0).vNombre = MyColumn
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Test As New MyObject
Test.add("TEST 001")
' HERE IS THE PROBLEM
Test("TEST 001")
' CORRECT USE
Test.MyExt("TEST 001")
End Sub
End Class
Now, my concrete question: How I can make a default extension in a specific Object?
#competent_tech: man you are a genius... thanks by your comment!
This is the solution of my problem:
Public Class ColumnData
Friend Name As String
Friend LastName As String
Friend Phone As String
End Class
Public Class MyColumns
Friend Data() As ColumnData
Default Property Item(ByVal ColumnName As String) As ColumnData
Get
Return Data(0)
End Get
Set(ByVal value As ColumnData)
End Set
End Property
Public Sub add(ByVal Name As String, ByVal LastName As String, ByVal Phone As String)
If Data Is Nothing Then
ReDim Data(0)
Data(0) = New ColumnData
End If
With Data(0)
.Name = Name
.LastName = LastName
.Phone = Phone
End With
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Test As New MyColumns
Test.add("Name 001", "bolanos.m", "500-2004-1000")
Debug.Print(Test("Name 001").LastName & " - " & Test("Name 001").Phone)
' bolanos.m - 500-2004-1000
Test("Name").LastName = "BOLANOS.M MODIFY"
Debug.Print(Test("Name 001").LastName & " - " & Test("Name 001").Phone)
' BOLANOS.M(MODIFY - 500 - 2004 - 1000)
End Sub
End Class

Why not just add default properties to the MyObject class?
Default Public Property IndexedColumn(index As String) As ColumnData
Get
Return Columns(index)
End Get
Set(value As ColumnData)
Columns(index) = value
End Set
End Property
Default Public Property IndexedColumn(index As Integer) As ColumnData
Get
Return Columns(index)
End Get
Set(value As ColumnData)
Columns(index) = value
End Set
End Property
You will need to change the exposure level of the structure and the access will be:
Dim oColumnData = Test("TEST 001")

Related

Get a value by index from combobox class

i'm approaching to vbnet from vb6 and i'm triyng to get value from combobox using a class which contains the values i stored in.
here is the class
Private m_ItemText As String
Private m_ItemIndex As Int32
Public Sub New(ByVal strItemText As String, ByVal intItemIndex As Int32)
m_ItemText = strItemText
m_ItemIndex = intItemIndex
End Sub
Public ReadOnly Property ItemIndex() As Int32
Get
Return m_ItemIndex
End Get
End Property
Public ReadOnly Property ItemText() As String
Get
Return m_ItemText
End Get
End Property
I use this method charge the combobox
ComboBox2.Items.Add(New clsComboBoxItem("sometext", 1))
ComboBox2.Items.Add(New clsComboBoxItem("sometext 2", 2))
ComboBox2.Items.Add(New clsComboBoxItem("sometext", 3))
and this on combobox.selectedindexchanged
If ComboBox2.SelectedItem.GetType.ToString = itmCombo.GetType.ToString Then
itmCombo = CType(ComboBox2.SelectedItem, clsComboBoxItem)
MessageBox.Show("Item Text=" & itmCombo.ItemText & " and ItemIndex=" & CStr(itmCombo.ItemIndex))
End If
Can anyone tell help me to understand how get an element by his index stored in the class? Eg writing '2' into a text box, the combo box sould be show "sometext2".
Suppose i want to expand the class adding some values, like m_ItemText2,m_ItemText3 etc, i would learn a method to get all of theese values.
I hope I was clear
Thanks in advance
If you have a DataSource set to a DataTable for your ComboBox, just set the DisplayMember and ValueMember. My test ComboBox is set to DropDownList.
Private Sub FillComboBox()
Dim dt As New DataTable
Using con As New SqlConnection(ConStr),
cmd As New SqlCommand("Select FlavorID,FlavorName From Flavors", con)
con.Open()
Using reader = cmd.ExecuteReader
dt.Load(reader)
End Using
End Using
ComboBox1.DisplayMember = "FlavorName"
ComboBox1.ValueMember = "FlavorID"
ComboBox1.DataSource = dt
End Sub
To display the the values
To display the Text cast to DataRowView (that is the object that is in the Item), provide the field you want and call ToString.
Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
MessageBox.Show(ComboBox1.SelectedValue.ToString)
MessageBox.Show(DirectCast(ComboBox1.SelectedItem, DataRowView)("FlavorName").ToString)
End Sub
If you are adding items one by one, you can still set the DisplayMember and ValueMember.
'https://stackoverflow.com/questions/38206678/set-displaymember-and-valuemember-on-combobox-without-datasource
Private Sub SomeFormsLoadEvent()
ComboBox1.Items.Add(New KeyValuePair(Of String, Integer)("Ultra-fast", 600))
ComboBox1.Items.Add(New KeyValuePair(Of String, Integer)("Fast", 300))
ComboBox1.Items.Add(New KeyValuePair(Of String, Integer)("Medium", 150))
ComboBox1.Items.Add(New KeyValuePair(Of String, Integer)("Slow", 75))
ComboBox1.DisplayMember = "Key"
ComboBox1.ValueMember = "Value"
ComboBox1.DataSource = ComboBox1.Items
End Sub
I found it a bit more complicated to display the text. I had to cast the item to its underlying type (KeyValuePair) then ask for the Key value.
Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
MessageBox.Show(ComboBox1.SelectedValue.ToString)
MessageBox.Show(DirectCast(ComboBox1.SelectedItem, KeyValuePair(Of String, Integer)).Key)
End Sub
As I understand it you want to store values in a class and display and access them through the combobox. How about this approach:
The class for the values:
Public Class clsValues
Private lstItemTexts As New List(Of String)
Public ReadOnly Property AllValues As List(Of String)
Get
Return lstItemTexts
End Get
End Property
'To initialize class with empty list, items can be added with AddItems
Public Sub New()
End Sub
'To initialize class with items, items can still be added with AddItems
Public Sub New(lstItemTexts As List(Of String))
Me.lstItemTexts = lstItemTexts
End Sub
Public Sub AddItem(item As String)
Me.lstItemTexts.Add(item)
End Sub
Public Function GetItemByIndex(index As Integer) As String
Return lstItemTexts(index)
End Function
Public Function GetIndexByItem(item As String) As Integer
Return lstItemTexts.IndexOf(item)
End Function
End Class
You can declare it and fill values like this:
Private Values As New clsValues()
Values.AddItem("Some Text 1")
Values.AddItem("Some Text 2")
or
Private Values As New clsValues(New List(Of String)({"Some Text 1", "Some Text 2"}))
to get a value from combobox
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
MessageBox.Show(Values.GetItemByIndex(ComboBox2.SelectedIndex))
End Sub
What #Mary stated is true the ComboBox has values that are useful SEE CODE BELOW
Change gvTxType to be a TextBox to see results when you click on the tvTxType
Private Sub cbTxType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbTxType.SelectedIndexChanged
If cbTxType.SelectedIndex > -1 Then
'Dim sindex As Integer
'sindex = cbTxType.SelectedIndex
'Dim sitem As String
sitem = CType(cbTxType.SelectedItem, String)
'MsgBox("You Selected " & sitem)
'Index is ZERO based
gvTxType = sitem
End If
End Sub

How can I print from an object?

I am having a problem getting my program to print an array. I have created a class with code and I want to be able to use the class to print the array. I have submitted my code below. hopefully Y'all can help me out thanks.
Option Strict On
Imports System.IO
Imports FinalLIB
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fsrFile As StreamReader = New StreamReader("Cars.csv")
Dim line, splitLine(1) As String
Dim bestCars(14) As Cars
Dim counter As Integer
Do Until fsrFile.EndOfStream
line = fsrFile.ReadLine
splitLine = Split(line, ",")
bestCars(counter) = New Cars(splitLine(0), (splitLine(1)), (splitLine(2)), (splitLine(3)))
counter += 1
Loop
Dim strCarMake, strCarModel, intyear, strColorc As Cars
Console.WriteLine(bestCars(3))
End Sub
This is the code from my library created.
Option Strict On
Public Class Cars
Private strCarMake As String
Private strCarModel As String
Private intYear As String
Private strColor As String
Public Sub New(ByVal bvstrCarMake As String, ByVal bvstrCarModel As String, ByVal bvintYear As String, ByVal bvstrColor As String)
prpCarMake = bvstrCarMake
prpYear = CInt(bvintYear)
prpCarModel = bvstrCarModel
prpColor = bvstrColor
End Sub
Public Property prpCarMake() As String
Get
Return strCarMake
End Get
Set(bvstrCarMake As String)
strCarMake = bvstrCarMake
End Set
End Property
Public Property prpCarModel() As String
Get
Return strCarModel
End Get
Set(bvstrCarModel As String)
strCarModel = bvstrCarModel
End Set
End Property
Public Property prpYear() As Integer
Get
Return CInt(intYear)
End Get
Set(bvintYear As Integer)
intYear = CType(bvintYear, String)
End Set
End Property
Public Property prpColor() As String
Get
Return strColor
End Get
Set(bvstrColor As String)
strColor = bvstrColor
End Set
End Property
Public ReadOnly Property prpIsOld() As Boolean
Get
If prpYear > 2010 Then
Return True
Else
Return False
End If
End Get
End Property
'Public ReadOnly Property prpSSN() As String
'Get
'Return strSSN
'End Get
'End Property
Public Function ReturnFullInfo() As String
Return "Make: " & prpCarMake & " Model: " & prpCarModel & "Year: " & prpYear & "Color: " & prpColor
End Function
End Class

VB.NET - Cannot bind to the new display member

I'm trying to assign the DataSource for a ComboBox that will allow the user to select a member. I'm receiving this error when run my application:
Cannot bind to the new display member.
Parameter name: newDisplayMember.
Here's my code:
Private Sub StartScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'GetAllELData()
ddlMember.DataSource = GetMemberList()
ddlMember.DisplayMember = "DisplayName"
ddlMember.ValueMember = "ID"
End Sub
Private Function GetMemberList() As List(Of Member)
Dim rval = New List(Of Member)
Dim dv As DataView = New DataView
Dim myConnString = ConfigurationSettings.AppSettings("ConnString")
Try
dv = SqlHelper.ExecuteDataset(myConnString, CommandType.StoredProcedure, "spGetData").Tables(0).DefaultView
Catch ex As Exception
MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK)
End Try
For Each row As DataRowView In dv
Dim mbrNum As String = row.Item("IMMBR_CD").ToString()
Dim mbrName As String = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(row.Item("IMMBR_NM20").ToLower())
Dim mbrState As String = row.Item("IMMBR_ST").ToString()
'assigns the member data to the list of members
rval.Add(New Member(mbrNum, mbrName, mbrState))
Next
Return rval
End Function
And then my class definition:
Public Class Member
Public ID As String
Public Name As String
Public State As String
Public DisplayName As String
Public Sub New(ByVal i As String, ByVal n As String, ByVal s As String)
ID = i
Name = n
State = s
DisplayName = ID & " - " & Name & ", " & State
End Sub
Public Overrides Function ToString() As String
Dim rval As String = ID & " - " & Name & ", " & State
Return rval
End Function
Public Function GetID() As String
Return ID
End Function
Public Function GetName() As String
Return Name
End Function
Public Function GetState() As String
Return State
End Function
End Class
I don't know why I'm getting the error. The application correctly loads the member as intended and works just fine once I click "Continue" on the error popup. Everything I've found about the error is for people passing a table as their DataSource instead of a custom class like me and the answers contain only code snippets rather than an explanation of the why there's a problem.
Can anyone help me figure out what's wrong here?
Thanks a bunch!
The errors were caused by binding directly to the fields. Defining those as properties and binding to the properties solved the issue.
Public ReadOnly Property GetID() As String
Get
Return Me.ID
End Get
End Property
Public ReadOnly Property GetName() As String
Get
Return Me.Name
End Get
End Property
Public ReadOnly Property GetState() As String
Get
Return Me.State
End Get
End Property
Public ReadOnly Property GetDisplayName() As String
Get
Return Me.DisplayName
End Get
End Property
And:
Private Sub StartScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'GetAllELData()
ddlMember.DataSource = GetMemberList()
ddlMember.DisplayMember = "GetDisplayName"
ddlMember.ValueMember = "GetID"
End Sub

Populating a combo box with a list of functions - Need Advice

I'm looking for some advice on the best way to handle this.
I have a list of about 200 "Functions" which are listed in a combo box. When the user selects a 'function' from the list, I need to return the functionID (integer).
I know this can be done easily by binding a dataset to the key and value of the combobox, I'm just not sure about the best way to populate the dataset.
I feel that the way I'm doing it currently is very convoluted:
I currently have a txt file as an embedded resource which I write to a temporary directory, then I use the following code to read in that text file and populate that box by setting the combobox's datasource and Display Member. It does this by way of a custom class which is implementing System.Collections.IList.
I have pasted the code below. The reason I want to simplify it is that I dislike writing the text file to the disk, because sometimes it fails.
I'm looking for a way to populate my combobox and return my ID, without writing anything to the user's temp folder.
I am open to changing the format of the embedded resource, and or the code.
The fnlist.txt is formatted currently as follows.
index, Function Name, ID
The index is only included for sorting (to keep NONE at the bottom, and unknown function at the top), and I suppose is not strictly required.
#Region "Function lookup"
Dim path As String = System.IO.Path.GetTempPath
Dim _objFnXtef As New clsFunctionXref(path & "fnList.txt")
Private Sub populate_list()
functionlist.DataSource = _objFnXtef
functionlist.DisplayMember = "StrFunction"
End Sub 'Populates the function list
Function get_index(ByVal fnid As Integer)
Dim iLookupNumber As Integer = fnid
Dim tmpFnInfo As New clsFunctionInfo
Dim iReturnIdx As Integer = -1
If iLookupNumber <> 0 Then
tmpFnInfo.IFunctionNumber = iLookupNumber
iReturnIdx = _objFnXtef.IndexOf(tmpFnInfo)
If iReturnIdx <> -1 Then
Return iReturnIdx - 1
Else
Return get_index(9999)
End If
End If
Return 0
End Function 'Returns index of specified function number
#End Region 'All function list functions
Here is the code when a user changes the drop down:
Private Sub functionlist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles functionlist.SelectedIndexChanged
Dim iReturnFuctionID As Integer = 0
Dim tmpFnInfo As New clsFunctionInfo
tmpFnInfo = _objFnXtef(functionlist.SelectedIndex)
iReturnFuctionID = tmpFnInfo.IFunctionNumber
Func = (iReturnFuctionID)
End Sub
And here is the supporting class:
Imports Microsoft.VisualBasic.FileIO
Public Class clsFunctionInfo
Private _idxFunction As Integer
Public Property IdxFunction() As Integer
Get
Return _idxFunction
End Get
Set(ByVal value As Integer)
_idxFunction = value
End Set
End Property
Private _strFunction As String
Public Property StrFunction() As String
Get
Return _strFunction
End Get
Set(ByVal value As String)
_strFunction = value
End Set
End Property
Private _iFunctionNumber As Integer
Public Property IFunctionNumber() As Integer
Get
Return _iFunctionNumber
End Get
Set(ByVal value As Integer)
_iFunctionNumber = value
End Set
End Property
End Class
Public Class clsFunctionXref
Implements System.Collections.IList
Private _colFunctionInfo As New Collection
Private _filePath As String
Public Property FilePath() As String
Get
Return _filePath
End Get
Set(ByVal value As String)
_filePath = value
End Set
End Property
Public Sub New(ByVal filename As String)
_filePath = filename
Dim _idx As Integer = 1
Dim fields As String()
Dim delimiter As String = ","
Dim iFnx As Integer
Using parser As New TextFieldParser(filename)
parser.SetDelimiters(delimiter)
While Not parser.EndOfData
' Read in the fields for the current line
fields = parser.ReadFields()
Try
iFnx = Convert.ToInt16(fields(0).ToString)
Catch ex As Exception
MessageBox.Show("Error reading file. " & ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim objFunction As New clsFunctionInfo
objFunction.IdxFunction = _idx
objFunction.IFunctionNumber = iFnx
objFunction.StrFunction = fields(1).ToString
Me.Add(objFunction)
_idx += 1
End While
End Using
End Sub
Public Function Add(ByVal value As Object) As Integer Implements System.Collections.IList.Add
If _colFunctionInfo.Contains(value.IFunctionNumber.ToString) Then
SyncLock Me.SyncRoot
_colFunctionInfo.Remove(value.IFunctionNumber.ToString)
End SyncLock
ReIndex()
End If
SyncLock Me.SyncRoot
_colFunctionInfo.Add(value, value.IFunctionNumber.ToString)
End SyncLock
End Function
Public Sub Clear() Implements System.Collections.IList.Clear
SyncLock Me.SyncRoot
_colFunctionInfo.Clear()
End SyncLock
End Sub
Public Function Contains(ByVal value As Object) As Boolean Implements System.Collections.IList.Contains
If _colFunctionInfo.Contains(value.IFunctionNumber.ToString) Then
Return True
Else
Return False
End If
End Function
Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
Get
Return _colFunctionInfo.Count
End Get
End Property
Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.IList.IsReadOnly
Get
Return False
End Get
End Property
Public Sub Remove(ByVal value As Object) Implements System.Collections.IList.Remove
If _colFunctionInfo.Contains(value.IFunctionNumber.ToString) Then
SyncLock Me.SyncRoot
_colFunctionInfo.Remove(value.IFunctionNumber.ToString)
End SyncLock
ReIndex()
End If
End Sub
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return _colFunctionInfo.GetEnumerator
End Function
Public Sub Insert(ByVal index As Integer, ByVal value As Object) Implements System.Collections.IList.Insert
SyncLock Me.SyncRoot
If _colFunctionInfo.Contains(value.IFunctionNumber.ToString) Then
_colFunctionInfo.Remove(value.IFunctionNumber.ToString)
End If
If index < _colFunctionInfo.Count Then
_colFunctionInfo.Add(value, value.IFunctionNumber.ToString, index - 1)
Else
_colFunctionInfo.Add(value, value.IFunctionNumber.ToString)
End If
End SyncLock
ReIndex()
End Sub
Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.IList.RemoveAt
SyncLock Me.SyncRoot
If _colFunctionInfo.Count <= index And index > 0 Then
_colFunctionInfo.Remove(index)
End If
End SyncLock
ReIndex()
End Sub
Private Sub ReIndex()
SyncLock Me.SyncRoot
Dim iReIndex As Integer = 1
Dim colTemp As New Collection
For Each obj As clsFunctionInfo In _colFunctionInfo
obj.IdxFunction = iReIndex
colTemp.Add(obj, obj.IFunctionNumber)
iReIndex += 1
Next
_colFunctionInfo.Clear()
For Each obj1 As clsFunctionInfo In colTemp
_colFunctionInfo.Add(obj1, obj1.IFunctionNumber.ToString)
Next
colTemp.Clear()
End SyncLock
End Sub
Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
Get
Return True
End Get
End Property
Public ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
Get
Dim _syncRoot As New Object
Return _syncRoot
End Get
End Property
Public ReadOnly Property IsFixedSize() As Boolean Implements System.Collections.IList.IsFixedSize
Get
Return False
End Get
End Property
Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo
For Each obj As clsFunctionInfo In _colFunctionInfo
array(index) = obj
index += 1
Next
End Sub
Public Function IndexOf(ByVal value As Object) As Integer Implements System.Collections.IList.IndexOf
SyncLock Me.SyncRoot
Dim tmpFnInfo As New clsFunctionInfo
Dim tmpFunctionNumber As Integer
Dim tmpidx As Integer = -1
tmpFnInfo = DirectCast(value, clsFunctionInfo)
tmpFunctionNumber = tmpFnInfo.IFunctionNumber
For Each obj In _colFunctionInfo
tmpFnInfo = DirectCast(obj, clsFunctionInfo)
If tmpFunctionNumber = tmpFnInfo.IFunctionNumber Then
tmpidx = tmpFnInfo.IdxFunction
Exit For
End If
Next
Return tmpidx
End SyncLock
End Function
Default Public Property Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item
Get
index += 1
Return _colFunctionInfo(index)
End Get
Set(ByVal value As Object)
End Set
End Property
End Class
I'm sorry that this is so long, but I know that someone on here has some great suggestions on how to handle this because I'm having a little trouble wrapping my head around it. I think I've been starring at it too long.
since you have the text file as an embedded resource, you can open a stream to the file from there, without having to write it to disk. The ResourceReader class should help you.

Problems building a DNN module using Linq to SQL

I am building a module using linq to SQL and I am running into some problems. I have been following Michal Washington's tutorial on adefwebserver.com. The problem is that VB does not recognize my Complaint Class when I try to create new Complaint object. Any idea why I am unable to Dim a Complaint object? Here is my code:
View.ascx.vb(
Imports Complaint
Protected Sub LinqDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) Handles LinqDataSource1.Inserting
Dim Complaint As **Complaint** = DirectCast(e.NewObject, Complaint)
Complaint.UserID = Entities.Users.UserController.GetCurrentUserInfo().Username
Complaint.ModuleId = ModuleId
Complaint.System_Time_Date_Stamp = Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss.fff")
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim Complaint As Complaint = (DirectCast((e.Row.DataItem), Complaint))
If (PortalSecurity.IsInRole("Administrators")) Then
e.Row.Cells(0).Enabled = True
Else
e.Row.Cells(0).Text = " "
End If
End If
End Sub
)
Complaint.designer.vb(
Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Reflection
Namespace Complaint
<System.Data.Linq.Mapping.DatabaseAttribute(Name:="NewDnn")> _
Partial Public Class ComplaintDataContext
Inherits System.Data.Linq.DataContext
Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource
#Region "Extensibility Method Definitions"
Partial Private Sub OnCreated()
End Sub
Partial Private Sub InsertComplaint(instance As Complaint)
End Sub
Partial Private Sub UpdateComplaint(instance As Complaint)
End Sub
Partial Private Sub DeleteComplaint(instance As Complaint)
End Sub
#End Region
Public Sub New()
MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As String)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As System.Data.IDbConnection)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As String, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public ReadOnly Property Complaints() As System.Data.Linq.Table(Of Complaint)
Get
Return Me.GetTable(Of Complaint)
End Get
End Property
End Class
<Table(Name:="dbo.Complaint")> _
Partial Public Class Complaint
Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
Private _ID As Integer
Private _ModuleID As System.Nullable(Of Integer)
Private _Member_UserName As String
Private _Reporter_Preffered_Contact As String
Private _Target_FName As String
Private _Target_LName As String
Private _Target_Street_Address As String
Private _Target_City As String
Private _Target_State As String
Private _Target_Zip As String
Private _Complaint_Details As String
Private _Status As String
Private _System_Time_Date_Stamp As System.Nullable(Of Date)
#Region "Extensibility Method Definitions"
Partial Private Sub OnLoaded()
End Sub
Partial Private Sub OnValidate(action As System.Data.Linq.ChangeAction)
End Sub
Partial Private Sub OnCreated()
End Sub
Partial Private Sub OnIDChanging(value As Integer)
End Sub
Partial Private Sub OnIDChanged()
End Sub
Partial Private Sub OnModuleIDChanging(value As System.Nullable(Of Integer))
End Sub
Partial Private Sub OnModuleIDChanged()
End Sub
Partial Private Sub OnMember_UserNameChanging(value As String)
End Sub
Partial Private Sub OnMember_UserNameChanged()
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanging(value As String)
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanged()
End Sub
Partial Private Sub OnTarget_FNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_FNameChanged()
End Sub
Partial Private Sub OnTarget_LNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_LNameChanged()
End Sub
Partial Private Sub OnTarget_Street_AddressChanging(value As String)
End Sub
Partial Private Sub OnTarget_Street_AddressChanged()
End Sub
Partial Private Sub OnTarget_CityChanging(value As String)
End Sub
Partial Private Sub OnTarget_CityChanged()
End Sub
Partial Private Sub OnTarget_StateChanging(value As String)
End Sub
Partial Private Sub OnTarget_StateChanged()
End Sub
Partial Private Sub OnTarget_ZipChanging(value As String)
End Sub
Partial Private Sub OnTarget_ZipChanged()
End Sub
Partial Private Sub OnComplaint_DetailsChanging(value As String)
End Sub
Partial Private Sub OnComplaint_DetailsChanged()
End Sub
Partial Private Sub OnStatusChanging(value As String)
End Sub
Partial Private Sub OnStatusChanged()
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanging(value As System.Nullable(Of Date))
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanged()
End Sub
#End Region
Public Sub New()
MyBase.New
OnCreated
End Sub
<Column(Storage:="_ID", AutoSync:=AutoSync.OnInsert, DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)> _
Public Property ID() As Integer
Get
Return Me._ID
End Get
Set
If ((Me._ID = value) _
= false) Then
Me.OnIDChanging(value)
Me.SendPropertyChanging
Me._ID = value
Me.SendPropertyChanged("ID")
Me.OnIDChanged
End If
End Set
End Property
<Column(Storage:="_ModuleID", DbType:="Int")> _
Public Property ModuleID() As System.Nullable(Of Integer)
Get
Return Me._ModuleID
End Get
Set
If (Me._ModuleID.Equals(value) = false) Then
Me.OnModuleIDChanging(value)
Me.SendPropertyChanging
Me._ModuleID = value
Me.SendPropertyChanged("ModuleID")
Me.OnModuleIDChanged
End If
End Set
End Property
<Column(Storage:="_Member_UserName", DbType:="NVarChar(50)")> _
Public Property Member_UserName() As String
Get
Return Me._Member_UserName
End Get
Set
If (String.Equals(Me._Member_UserName, value) = false) Then
Me.OnMember_UserNameChanging(value)
Me.SendPropertyChanging
Me._Member_UserName = value
Me.SendPropertyChanged("Member_UserName")
Me.OnMember_UserNameChanged
End If
End Set
End Property
<Column(Storage:="_Reporter_Preffered_Contact", DbType:="NVarChar(50)")> _
Public Property Reporter_Preffered_Contact() As String
Get
Return Me._Reporter_Preffered_Contact
End Get
Set
If (String.Equals(Me._Reporter_Preffered_Contact, value) = false) Then
Me.OnReporter_Preffered_ContactChanging(value)
Me.SendPropertyChanging
Me._Reporter_Preffered_Contact = value
Me.SendPropertyChanged("Reporter_Preffered_Contact")
Me.OnReporter_Preffered_ContactChanged
End If
End Set
End Property
<Column(Storage:="_Target_FName", DbType:="NVarChar(50)")> _
Public Property Target_FName() As String
Get
Return Me._Target_FName
End Get
Set
If (String.Equals(Me._Target_FName, value) = false) Then
Me.OnTarget_FNameChanging(value)
Me.SendPropertyChanging
Me._Target_FName = value
Me.SendPropertyChanged("Target_FName")
Me.OnTarget_FNameChanged
End If
End Set
End Property
<Column(Storage:="_Target_LName", DbType:="NVarChar(50)")> _
Public Property Target_LName() As String
Get
Return Me._Target_LName
End Get
Set
If (String.Equals(Me._Target_LName, value) = false) Then
Me.OnTarget_LNameChanging(value)
Me.SendPropertyChanging
Me._Target_LName = value
Me.SendPropertyChanged("Target_LName")
Me.OnTarget_LNameChanged
End If
End Set
End Property
<Column(Storage:="_Target_Street_Address", DbType:="NVarChar(100)")> _
Public Property Target_Street_Address() As String
Get
Return Me._Target_Street_Address
End Get
Set
If (String.Equals(Me._Target_Street_Address, value) = false) Then
Me.OnTarget_Street_AddressChanging(value)
Me.SendPropertyChanging
Me._Target_Street_Address = value
Me.SendPropertyChanged("Target_Street_Address")
Me.OnTarget_Street_AddressChanged
End If
End Set
End Property
<Column(Storage:="_Target_City", DbType:="NVarChar(50)")> _
Public Property Target_City() As String
Get
Return Me._Target_City
End Get
Set
If (String.Equals(Me._Target_City, value) = false) Then
Me.OnTarget_CityChanging(value)
Me.SendPropertyChanging
Me._Target_City = value
Me.SendPropertyChanged("Target_City")
Me.OnTarget_CityChanged
End If
End Set
End Property
<Column(Storage:="_Target_State", DbType:="NVarChar(50)")> _
Public Property Target_State() As String
Get
Return Me._Target_State
End Get
Set
If (String.Equals(Me._Target_State, value) = false) Then
Me.OnTarget_StateChanging(value)
Me.SendPropertyChanging
Me._Target_State = value
Me.SendPropertyChanged("Target_State")
Me.OnTarget_StateChanged
End If
End Set
End Property
<Column(Storage:="_Target_Zip", DbType:="NVarChar(50)")> _
Public Property Target_Zip() As String
Get
Return Me._Target_Zip
End Get
Set
If (String.Equals(Me._Target_Zip, value) = false) Then
Me.OnTarget_ZipChanging(value)
Me.SendPropertyChanging
Me._Target_Zip = value
Me.SendPropertyChanged("Target_Zip")
Me.OnTarget_ZipChanged
End If
End Set
End Property
<Column(Storage:="_Complaint_Details", DbType:="NVarChar(4000)")> _
Public Property Complaint_Details() As String
Get
Return Me._Complaint_Details
End Get
Set
If (String.Equals(Me._Complaint_Details, value) = false) Then
Me.OnComplaint_DetailsChanging(value)
Me.SendPropertyChanging
Me._Complaint_Details = value
Me.SendPropertyChanged("Complaint_Details")
Me.OnComplaint_DetailsChanged
End If
End Set
End Property
<Column(Storage:="_Status", DbType:="NVarChar(4000)")> _
Public Property Status() As String
Get
Return Me._Status
End Get
Set
If (String.Equals(Me._Status, value) = false) Then
Me.OnStatusChanging(value)
Me.SendPropertyChanging
Me._Status = value
Me.SendPropertyChanged("Status")
Me.OnStatusChanged
End If
End Set
End Property
<Column(Storage:="_System_Time_Date_Stamp", DbType:="DateTime")> _
Public Property System_Time_Date_Stamp() As System.Nullable(Of Date)
Get
Return Me._System_Time_Date_Stamp
End Get
Set
If (Me._System_Time_Date_Stamp.Equals(value) = false) Then
Me.OnSystem_Time_Date_StampChanging(value)
Me.SendPropertyChanging
Me._System_Time_Date_Stamp = value
Me.SendPropertyChanged("System_Time_Date_Stamp")
Me.OnSystem_Time_Date_StampChanged
End If
End Set
End Property
Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging
Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub SendPropertyChanging()
If ((Me.PropertyChangingEvent Is Nothing) _
= false) Then
RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
End If
End Sub
Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
If ((Me.PropertyChangedEvent Is Nothing) _
= false) Then
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End If
End Sub
End Class
End Namespace
)
Using "Complaint" as the NameSpace, Class name, and Object name is a bad idea and might be causing your problem. I know you can name the variable the same as the class in C# but I'm not sure it's legal in VB.NET, it's not something I do since it can be confusing on whether you're referring to the instance or the class.
I ran into an issue similar to this. My app code was in a folder above my DesktopModules folder, so the designer put the incorrect namespace in my designer.vb file.
All of my other .vb files had
Namespace Modules.CGaming
but the auto generated one only had
Namespace CGaming
Once I modified the namespace on my designer.vb file, it was available in the context.
Hope this helps!