Infragistics UltraGrid summary value from cell - vb.net

I have this ultraGrid:
http://s4.postimg.org/fhnjs4w4d/Capture.png
I need to pass to summary cell a custom value from column with red mark on picture.
Infragistics lets me put the Max, Min, Sum, Average, etc in summary cell, but I need to pass custom value.
Any help?
I have this code wich put Max value:
Dim columnToSummarizeVlrAq As UltraGridColumn = ugbBens.DisplayLayout.Bands(0).Columns(ugbBensColVlrAq)
Dim summaryVlrAq As SummarySettings = .Add(ugbBensColVlrAq,SummaryType.Maximum, columnToSummarizeVlrAq, SummaryPosition.UseSummaryPositionColumn)
Here the solution :
Create a new class:
Public Class MyCustomSummarySettings
Implements ICustomSummaryCalculator
Private valor As Object = 0
Public Sub New()
End Sub
Public Sub Val()
End Sub
Private Sub BeginCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.BeginCustomSummary
valor = 0
End Sub
Private Sub AggregateCustomSummary(ByVal summarySettings As SummarySettings, ByVal row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary
'Primeiro mês
If summarySettings.Key = "COL_DeprAntExVlrRv" Then
If row.Index = 0 Then valor = CDbl(row.Cells("COL_DeprAntExVlrRv").Value)
End If
If summarySettings.Key = "fltVlrDepreciavelAct" Then
If row.Index = 0 Then valor = CDbl(row.Cells("fltVlrDepreciavelAct").Value)
End If
End Sub
Private Function EndCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) As Object Implements ICustomSummaryCalculator.EndCustomSummary
Return valor
End Function
End Class
And call class with summary type custom, like this:
Dim custumSummary As New MyCustomSummarySettings
summaryDepreciavel = .Add(ugbBensColDepreciavelAceite, SummaryType.Custom, custumSummary, columnToSummarizeDepreciavel, SummaryPosition.UseSummaryPositionColumn, Nothing) '7ª Coluna

Dim custumSummary As New MyCustomSummarySettings
summaryDepreciavel = .Add(ugbBensColDepreciavelAceite, SummaryType.Custom, custumSummary, columnToSummarizeDepreciavel, SummaryPosition.UseSummaryPositionColumn, Nothing)

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

Search dgv column by Column("TagIndex = 5")

I'm trying to get data from a DGV grid onto specific tags, and so far it has been working great. But an update moved the tags positions in the DGV so Rows(x) does not equal the tags I'm moving data into anymore.
Is it possible to do a search like the one I'm doing in Cells("Val") but in the Rows("") instead?
Actually I want it to be something like this Rows("TagIndex = 5") etc.
A full line of code would then be:
HopperStatus = dgvDataFlt.Rows("TagIndex = 5").Cells("Val").Value
but is this possible.
Row 12 & 13 are switched when logging
dgvDataFLT = dgvDataFloating
If dgvDataFlt.Rows(0).Cells("TagIndex").Value = 12 Then
'DGVDataFlt.AutoResizeColumns()
'--------------------------------------Floating TAGS fra database------------------------------------------
ProdRecCnt = dgvDataFlt.Rows(10).Cells("Val").Value
ProdTotCnt = dgvDataFlt.Rows(9).Cells("Val").Value
FrontFree = dgvDataFlt.Rows(8).Cells("Val").Value
CurrAutoMode = dgvDataFlt.Rows(7).Cells("Val").Value
PalletStatus = dgvDataFlt.Rows(6).Cells("Val").Value
HopperStatus = dgvDataFlt.Rows(5).Cells("Val").Value
PowerStatus = dgvDataFlt.Rows(4).Cells("Val").Value
CurrRecNo = dgvDataFlt.Rows(3).Cells("Val").Value
NomCycTime = dgvDataFlt.Rows(2).Cells("Val").Value
AutoStart = dgvDataFlt.Rows(1).Cells("Val").Value
MachineNo = dgvDataFlt.Rows(0).Cells("Val").Value
LOGTimeStamp = dgvDataFlt.Rows(0).Cells("DateAndTime").Value 'for aktuelle lognings tidstempel
LOGDateStamp = Microsoft.VisualBasic.Left(LOGTimeStamp, 10)
LOGClockStamp = Microsoft.VisualBasic.Mid(LOGTimeStamp, 12, 5)
End If
I want the code to look/work something like this:
If dgvDataFlt.Rows(0).Cells("TagIndex").Value = 12 Then
'DGVDataFlt.AutoResizeColumns()
'--------------------------------------Floating TAGS fra database------------------------------------------
ProdRecCnt = dgvDataFlt.Rows("TagIndex = 10").Cells("Val").Value
ProdTotCnt = dgvDataFlt.Rows("TagIndex = 9").Cells("Val").Value
FrontFree = dgvDataFlt.Rows("TagIndex = 8").Cells("Val").Value
CurrAutoMode = dgvDataFlt.Rows("TagIndex = 7").Cells("Val").Value
PalletStatus = dgvDataFlt.Rows("TagIndex = 6").Cells("Val").Value
HopperStatus = dgvDataFlt.Rows("TagIndex = 5").Cells("Val").Value
PowerStatus = dgvDataFlt.Rows("TagIndex = 4").Cells("Val").Value
CurrRecNo = dgvDataFlt.Rows("TagIndex = 3").Cells("Val").Value
NomCycTime = dgvDataFlt.Rows("TagIndex = 2").Cells("Val").Value
AutoStart = dgvDataFlt.Rows("TagIndex = 1").Cells("Val").Value
MachineNo = dgvDataFlt.Rows("TagIndex = 0").Cells("Val").Value
LOGTimeStamp = dgvDataFlt.Rows(0).Cells("DateAndTime").Value 'for aktuelle lognings tidstempel
LOGDateStamp = Microsoft.VisualBasic.Left(LOGTimeStamp, 10)
LOGClockStamp = Microsoft.VisualBasic.Mid(LOGTimeStamp, 12, 5)
End If
I would suggest adding a class and then inheriting the DataGridView control into that class. I have made a quick little example of this and the code works, but to get it to work you will have to perform a few steps:
(1) If you don't already have a windows forms application to test this then,
make a new one.
(2) Create class named KeyedDataGridView
(3) Copy and Paste the following Code into KeyedDataGridView class
(4) Rebuild your Project
(5) Drag and Drop new component onto your windows Form.
NOTE: This class is limited, but should still be able to do what you require of it.
Finally, if you need any help then, please leave a comment and will try to get to it when I can.
Option Explicit On
Public Class KeyedDataGridView
Inherits Windows.Forms.DataGridView
Dim _Rows As KeyedDataRows
Public Shadows Property Rows As KeyedDataRows
Get
Return _Rows
End Get
Set(value As KeyedDataRows)
_Rows = value
End Set
End Property
Public Sub New()
Dim strName As String
strName = Me.Name
strName = MyBase.Name
_Rows = New KeyedDataRows(Me)
_Rows.Rows = MyBase.Rows
End Sub
Protected Overrides Sub Finalize()
_Rows = Nothing
MyBase.Finalize()
End Sub
End Class
Public Class KeyedDataRows
Inherits Windows.Forms.DataGridViewRowCollection
Dim _TagNames As Dictionary(Of String, Integer)
Dim _Rows As DataGridViewRowCollection
Dim _Cells As Dictionary(Of String, DataGridViewCellCollection)
Dim dgv As DataGridView
Default Public Overloads ReadOnly Property Item(strTagName As String) As DataGridViewRow
Get
Return _Rows.Item(Me.IndexFromName(strTagName))
End Get
End Property
Protected Friend Property Rows As DataGridViewRowCollection
Get
Return _Rows
End Get
Set(value As DataGridViewRowCollection)
_Rows = value
End Set
End Property
Public Property TagName(index As Integer) As String
Get
Return CStr(_TagNames.Item(index))
End Get
Set(value As String)
_TagNames.Item(index) = value
End Set
End Property
Public Sub New(tmp As DataGridView)
MyBase.New(tmp)
dgv = tmp
_TagNames = New Dictionary(Of String, Integer)
_Cells = New Dictionary(Of String, DataGridViewCellCollection)
End Sub
Public Shadows Sub Add(strTagName As String)
Dim intCurRow As Integer
If dgv.AllowUserToAddRows Then
intCurRow = _Rows.Count - 1
Else
intCurRow = _Rows.Count
End If
_TagNames.Add(strTagName, intCurRow)
_Rows.Add()
End Sub
Public Shadows Sub Add(strTagName As String, dataGridViewRow As DataGridViewRow)
Dim intCurRow As Integer
If dgv.AllowUserToAddRows Then
intCurRow = _Rows.Count - 1
Else
intCurRow = _Rows.Count
End If
_TagNames.Add(strTagName, intCurRow)
_Rows.Add(dataGridViewRow)
End Sub
Public Shadows Sub Add(count As Integer, strTagNames() As String)
Dim intI As Integer
Dim intCurRow As Integer
If dgv.AllowUserToAddRows Then
intCurRow = _Rows.Count - 1
Else
intCurRow = _Rows.Count
End If
For intI = 0 To (count - 1)
_TagNames.Add(strTagNames(intI), intCurRow)
_Rows.Add()
intCurRow = _Rows.Count - 1
Next intI
End Sub
Public Property IndexFromName(strTagName As String) As Integer
Get
If _TagNames.Count > 0 Then
If _TagNames.ContainsKey(strTagName) Then
Return _TagNames.Item(strTagName)
Else
Return -1
End If
Else
Return -1
End If
End Get
Set(value As Integer)
_TagNames.Add(strTagName, value)
End Set
End Property
Public Overloads Sub RemoveAt(strTagName As String)
_Cells.Remove(strTagName)
_Rows.RemoveAt(IndexFromName(strTagName))
_TagNames.Remove(strTagName)
End Sub
Protected Overrides Sub Finalize()
_TagNames.Clear()
_TagNames = Nothing
_Cells.Clear()
_Rows.Clear()
_Cells = Nothing
_Rows = Nothing
MyBase.Finalize()
End Sub
End Class
I also, added the following buttons to a windows form to test the code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
With KeyedDataGridView1
.Rows.Add("Tag Test 1")
.Rows.Add("Tag Test 2")
.Rows.Add("Tag Test 3")
.Rows.Add("Tag Test 4")
End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox(KeyedDataGridView1.Rows("Tag Test 3").Cells(0).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 3").Cells(1).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 3").Cells(2).Value)
MsgBox(KeyedDataGridView1.Rows("Tag Test 2").Cells(0).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 2").Cells(1).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 2").Cells(2).Value)
MsgBox(KeyedDataGridView1.Rows("Tag Test 1").Cells(0).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 1").Cells(1).Value & vbCrLf &
KeyedDataGridView1.Rows("Tag Test 1").Cells(2).Value)
End Sub

Adding List of Objects to Dropdown Combobox in Visual Basic

I am pretty new to Visual Basic and mostly create through trial and error but I've been attempting this for about 5 hours now and have had no luck. I am trying to create a program used at events for runners. It has multiple forms. There are two forms to create Runners and Races. These are then stored in the Runner and Race Collection Lists. I want to populate a dropdown box with the races that are stored in the race collection list. The closet I have got to achieving this so far is the dropdown displaying "{}collection". I have tried .datasource, .add and .addRange. None seem to work.
My race collection code is:
Public Class RaceList
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal aRace As Race, Optional ByVal key As String = "NewRace")
List.Add(aRace)
End Sub
Public ReadOnly Property Item(ByVal index As Integer) As Race
Get
Return CType(List.Item(index), Race)
End Get
End Property
End Class
it should simply allow the user to add too and return races in the list.
Here is the code that allows the user to add a race to the list:
Public Class newRaceForm
Public Shared racelist As New RaceList
Private Sub uiBtnAddNewRace_Click(sender As System.Object, e As System.EventArgs) Handles uiBtnAddNewRace.Click
uiDTPRaceDate.Text = Today
Dim x As Date
Dim champ As Boolean = False
x = uiDTPRaceDate.Text
If uiCheckboxChampion.Checked = True Then
champ = True
End If
Dim race As New Race(x, champ)
uiCheckboxChampion.Checked = False
MsgBox("Race Added")
racelist.Add(race, race.uniqueRaceID)
End Sub
Finally, Here is the code on the form_load that should populate the box with the contents of racelist.
Private Sub finishRaceForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim x = 0
Dim races As New RaceList
While x < races.Count
uiDropDownRace.Items.Add(races.Item(x).ToString)
x = x + 1
End While
End Sub
Also, my races class is created as such:
Public Class Race
Private raceDate As String
Private isChampionship As Boolean
Public Shared RaceID As Integer = 0
Public uniqueRaceID As String
Sub New(ByVal x As String, champ As Boolean)
raceDate = x
If champ = True Then
isChampionship = True
Else
isChampionship = False
End If
RaceID = RaceID + 1
uniqueRaceID = "RaceID0" + RaceID.ToString
End Sub
End Class
Whenever you add an object to a list box or drop down list, the the ToString function is called, to determine what is going to be shown.
Most objects default to returning their type name as their ToString Function. You can overrride the ToString function to display whatever you wish. In the example below, I display the text "Race Number x" where x is the race number.
Public Class Race
Private raceDate As String
Private isChampionship As Boolean
Public Shared RaceID As Integer = 0
Public uniqueRaceID As String
Sub New(ByVal x As String, champ As Boolean)
raceDate = x
If champ = True Then
isChampionship = True
Else
isChampionship = False
End If
RaceID = RaceID + 1
uniqueRaceID = "RaceID0" + RaceID.ToString
End Sub
Public Overloads Function ToString() As String
Return "Race Number " & RaceID.ToString()
End Function
End Class
I'm working on a similar program and got it to work by using this.
Dim CmbAcro As String() = {"INSERT", "THE", "ITEMS", "YOU", "WANT", "TO", "ADD", "TO", "A", "COMBO", "BOX"}
Dim cmb As New DataGridViewComboBoxColumn()
cmb.HeaderText = "INSERT HEADER TEXT HERE"
cmb.Name = "INSERT NAME HERE"
cmb.MaxDropDownItems = 20
cmb.Sorted = True
For Each i In CmbAcro
cmb.Items.Add(i)
Next
DataGridView1.Columns.Add(cmb)

ArrayList change values when i add a new one VB.NET

So here is my problem. I have a Class of Products and i have created an ArrayList of that class.
I can add lot of new Products to that Array but the problem is that the Array change all the Values of the Array as the last one i have added.
Product Class:
Public Class Product
Dim cod_prod As String
Dim state As Boolean
Public Sub New(ByVal cod As String, ByVal est As Boolean)
cod_prod = cod
state = est
End Sub
Public Sub New()
cod_prod = ""
state = False
End Sub
Public Function get_cod_prod() As String
Return cod_prod
End Function
Public Function get_state() As Boolean
Return state
End Function
Public Sub set_cod_prod(ByVal cod As String)
cod_prod = cod
End Sub
Public Sub set_state(ByVal est As Boolean)
state = est
End Sub
End Class
And this class is were i add a new Product to the ArrayList.
Dim array_prod As New ArrayList
Dim nproducts As Integer = 0
Public Sub add_prod(ByVal prod As Producto)
array_prod.Add(prod)
nproducts += 1
End Sub
Thanks for help.
Ok, looking a bit more on related questions i have found this.
Retrieving data from a VB.NET arraylist of objects
So i solve it changing the method like this:
Public Sub add_prod(ByVal prod As Producto)
Dim nprod As New Producto
nprod.set_cod_prod(prod.get_cod_prod)
nprod.set_state(prod.get_state)
array_prod.Add(nprod)
nproductos += 1
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.