login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Wijziging van een List(of T) zonder opdracht daar voor.

Offline MrWolf - 06/01/2010 16:22 (laatste wijziging 06/01/2010 17:12)
Avatar van MrWolfLid In mijn programma kan je via een listview kiezen welk sub-programma je wilt starten. Deze programma's staan beschreven in .mdl bestanden in de map \Modules.

Ik heb de onderstaande code. Deze werkt niet, want na tijdens de for each is eerst externalmodulecollection(0).FileName [...]\Modules\IGC.mdl. In de 2e keer dat hij er langs gaat is externalmodulecollection(0).FileName ineens [...]\Modules\IGSW.mdl.

Gedeelte van de code van Form1
  1. Public Class Form1
  2. Dim externalmodulecollection As New List(Of ExternalModule)
  3. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4. ListView1.Items.Clear()
  5. Dim _map As New IO.DirectoryInfo(GetAppPath() + "\modules")
  6. Dim _arrayFiles As IO.FileInfo() = _map.GetFiles("*.mdl")
  7. Dim _info As IO.FileInfo
  8. For Each _info In _arrayFiles
  9. Dim itm As New ExternalModule
  10. itm.FileName = _info.FullName
  11. itm.Read()
  12. ImageList1.Images.Add(itm.FileName, New Bitmap(My.Computer.FileSystem.GetParentPath(itm.FileName) + "\" + itm.Image))
  13. Dim LVitm As New ListViewItem(itm.ProgName, ImageList1.Images.Count - 1)
  14. ListView1.Items.Add(LVitm)
  15. externalmodulecollection.Add(itm)
  16. Try
  17. MsgBox(externalmodulecollection(0).FileName)
  18. MsgBox(externalmodulecollection(1).FileName) 'Klein testje!
  19. MsgBox(externalmodulecollection(2).FileName)
  20. Catch ex As Exception
  21. MsgBox("")
  22. End Try
  23. Next
  24. Dim this As New ListViewItem("", 0)
  25. ListView1_SelectedIndexChanged()
  26. End Sub

En een gedeelte uit de module waar Externalmodule in is gedeclareerd:
  1. Imports System.Windows.Forms
  2. Imports System.Reflection
  3.  
  4. Module M_Load_Externall_Dll
  5. Public Structure ExternalModule
  6. Shared fn As New String("")
  7. Shared nm As New String("")
  8. Shared ds As New String("")
  9. Shared img As New String("")
  10. Shared dll As New String("")
  11. Public Sub SetFileName(ByVal NewFileName As String)
  12. FileName = NewFileName
  13. End Sub
  14. Public Property FileName() As String
  15. Get
  16. FileName = fn
  17.  
  18. End Get
  19. Set(ByVal value As String)
  20. fn = value
  21. End Set
  22. End Property
  23. Public Property ProgName() As String
  24. Get
  25. ProgName = nm
  26. End Get
  27. Set(ByVal value As String)
  28. nm = value
  29. End Set
  30. End Property
  31. Public Property Description() As String
  32. Get
  33. Description = ds
  34. End Get
  35. Set(ByVal value As String)
  36. ds = value
  37. End Set
  38. End Property
  39. Public Property Image() As String
  40. Get
  41. Image = img
  42. End Get
  43. Set(ByVal value As String)
  44. img = value
  45. End Set
  46. End Property
  47. Public Property DllFile() As String
  48. Get
  49. DllFile = dll
  50. End Get
  51. Set(ByVal value As String)
  52. dll = value
  53. End Set
  54. End Property
  55. Public Function Read() As Boolean
  56. Try
  57. Dim ta() As String = My.Computer.FileSystem.ReadAllText(fn).Split("&")
  58. nm = ta(0)
  59. ds = ta(1)
  60. img = ta(2)
  61. dll = ta(3)
  62. RaiseEvent ReadCompleted()
  63. Read = True
  64. Catch ex As Exception
  65. RaiseEvent ReadError()
  66. Read = False
  67. End Try
  68. End Function
  69. Public Event ReadError()
  70. Public Event ReadCompleted()
  71. End Structure


Inhoud van de map \Modules:
IGC.mdl
IGC.png
IGSW.mdl
IGSW.png

Inhoud van IGC.mdl
IGisoft Converter 2010&Reken getallen van de ene naar de andere eenheid om&IGC.png&IGC.dll

Inhoud van IGSW.mdl
IGisoft Stopwatch 2010&Meet tijden&IGSW.png&IGSW.dll

Iemand een oplossing zodat de List niet ineens veranderd?

4 antwoorden

Gesponsorde links
Offline Mario - 07/01/2010 09:41
Avatar van Mario Crew algemeen MrWolf,

Ik heb dit even bekeken en de code opgebouwd (zie link) aan de hand van hetgeen je hierboven post.

Jouw probleem kom ik echter niet tegen, ik krijg elke keer hetzelfde resultaat.

PS : welke versie van .net gebruik je ?

http://users.telenet.be/redthread/sitemasters
Offline MrWolf - 07/01/2010 14:41 (laatste wijziging 07/01/2010 15:11)
Avatar van MrWolf Lid 3.5 in VS 2008

Het werkt nog niet. Dezelfde fout (Eerst is externalmodulecollection(0).FileName [...]\Modules\IGC.mdl, Daarna is externalmodulecollection(0).FileName ineens [...]\Modules\IGSW.mdl ) ...
Offline Mario - 07/01/2010 16:20
Avatar van Mario Crew algemeen Maar je draait een loop van _arrayFiles waar inderdaad 2 files instaan (je filter staat op *.mdl)

Wat zou er volgens jou dan moeten gebeuren ?
Offline MrWolf - 07/01/2010 16:52
Avatar van MrWolf Lid
Mario schreef:
Maar je draait een loop van _arrayFiles waar inderdaad 2 files instaan (je filter staat op *.mdl)

Dat klopt.

Maar wat voor MsgBox's krijg jij?
Ik krijg
[...]\Modules\IGC.mdl
[...]\Modules\IGSW.mdl

Terwijl ik volgens mij
[...]\Modules\IGC.mdl
[...]\Modules\IGC.mdl
moet krijgen. Want externalmodulecollection(0) word de 2e keer aangepast, maar dat moet niet!
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.247s