Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Visual Studio VB.NET help
New Posts  All Forums:Forum Nav:

Visual Studio VB.NET help

post #1 of 8
Thread Starter 
I'm trying something that seems really simple, having a listbox/combobox display some data. Here's the code:
Quote:
Public Class Form1
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox1.Items.Add("TSJ")
End Sub
End Class

I don't understand why this comes up with the listbox/combobox empty. The box only seems to show anything if I visually add items (by right clicking on the box and selecting "Edit Items".
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
post #2 of 8
Quote:
Originally Posted by kurt1288;15204434 
I'm trying something that seems really simple, having a listbox/combobox display some data. Here's the code:


I don't understand why this comes up with the listbox/combobox empty. The box only seems to show anything if I visually add items (by right clicking on the box and selecting "Edit Items".

You need to put the "ListBox1.Items.Add("TSJ")" in some other event such as a button click or the form load. Private Sub ListBox1_SelectedIndexChanged fires when the value of the listbox is changed.
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
post #3 of 8
That code will only add that item if the item you've selected in the list changes.

What are you try to do? Make it add data entries from a dataset or what?
Maximum Dwarf
(15 items)
 
Density!
(12 items)
 
 
CPUMotherboardGraphicsRAM
i5-3570k ASUS MAXIMUS IV GENE HD7970 Gen 1 Ripjaws Z 2x8GB 2133MHz 
Hard DriveHard DriveOptical DriveCooling
1TB RE4 2x3TB WD Red LG 10x BD-R Corsair H80i w/push pull 
OSMonitorKeyboardPower
Win 7 Ultimate 3x 1920x1080 LG IPS displays. Razer Mass Effect 3 Blackwidow Ultimate Cooler Master Silent Pro M850 
CaseMouseMouse Pad
Silverstone TJ08B-E R.A.T. 7 An ergonomic one 
CPUMotherboardRAMHard Drive
i7 3770k Gigabyte Sniper M3 1155 mATX CORSAIR Vengeance 8GB (2 x 4GB) 1600MHz 1TB WD RE4 
Hard DriveHard DriveHard DriveHard Drive
2TB WD Red 2TB WD Red 4TB WD Red 4TB WD Red 
PowerCaseAudioOther
750W Seasonic Gold Fractal Node 804 5.1 Definitive Def Tech PERC 5i RAID card w/ BBU (LSI Firmware) 
  hide details  
Reply
Maximum Dwarf
(15 items)
 
Density!
(12 items)
 
 
CPUMotherboardGraphicsRAM
i5-3570k ASUS MAXIMUS IV GENE HD7970 Gen 1 Ripjaws Z 2x8GB 2133MHz 
Hard DriveHard DriveOptical DriveCooling
1TB RE4 2x3TB WD Red LG 10x BD-R Corsair H80i w/push pull 
OSMonitorKeyboardPower
Win 7 Ultimate 3x 1920x1080 LG IPS displays. Razer Mass Effect 3 Blackwidow Ultimate Cooler Master Silent Pro M850 
CaseMouseMouse Pad
Silverstone TJ08B-E R.A.T. 7 An ergonomic one 
CPUMotherboardRAMHard Drive
i7 3770k Gigabyte Sniper M3 1155 mATX CORSAIR Vengeance 8GB (2 x 4GB) 1600MHz 1TB WD RE4 
Hard DriveHard DriveHard DriveHard Drive
2TB WD Red 2TB WD Red 4TB WD Red 4TB WD Red 
PowerCaseAudioOther
750W Seasonic Gold Fractal Node 804 5.1 Definitive Def Tech PERC 5i RAID card w/ BBU (LSI Firmware) 
  hide details  
Reply
post #4 of 8
Thread Starter 
Ultimately I want to add items to the list that are located in a folder on the computer. For now, I'd be satisfied with understanding how to populate the list with just static data like above.
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
post #5 of 8
Write your own function that will load your list box and call the function in the load will be an easy way to start it. From there you can change that function to grab the list from your folder and won't have to make huge code changes in the form load.
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
post #6 of 8
The easiest method that I've found is to load the desired list (that you want to populate) into a dataset and then write a while statement to enter each entry from the dataset into the listbox.

For Example:
Quote:
dsLocationResults.Clear()
dsLocationResults.Tables.Clear()
objDataAdapter2.Fill(dsLocationResults)
If dsLocationResults.Tables(0).Rows.Count <> 0 Then
Dim count As Integer = 0
While count <= dsLocationResults.Tables(0).Rows.Count - 1
ListBox1.Items.Add(dsLocationResults.Tables(0).Rows(count).Item(0))
ListBox2.Items.Add("Phone: " & dsLocationResults.Tables(0).Rows(count).Item(1) & " Fax: " & dsLocationResults.Tables(0).Rows(count).Item(2) & " Website: " & dsLocationResults.Tables(0).Rows(count).Item(5))
count = count + 1
End While
Else
MsgBox("No results found")
End If
where dsLocationResults is the dataset I'm loading into the listbox (in my program this dataset is filled from a SQL search query that I made, that ran under objDataAdapter2)
Maximum Dwarf
(15 items)
 
Density!
(12 items)
 
 
CPUMotherboardGraphicsRAM
i5-3570k ASUS MAXIMUS IV GENE HD7970 Gen 1 Ripjaws Z 2x8GB 2133MHz 
Hard DriveHard DriveOptical DriveCooling
1TB RE4 2x3TB WD Red LG 10x BD-R Corsair H80i w/push pull 
OSMonitorKeyboardPower
Win 7 Ultimate 3x 1920x1080 LG IPS displays. Razer Mass Effect 3 Blackwidow Ultimate Cooler Master Silent Pro M850 
CaseMouseMouse Pad
Silverstone TJ08B-E R.A.T. 7 An ergonomic one 
CPUMotherboardRAMHard Drive
i7 3770k Gigabyte Sniper M3 1155 mATX CORSAIR Vengeance 8GB (2 x 4GB) 1600MHz 1TB WD RE4 
Hard DriveHard DriveHard DriveHard Drive
2TB WD Red 2TB WD Red 4TB WD Red 4TB WD Red 
PowerCaseAudioOther
750W Seasonic Gold Fractal Node 804 5.1 Definitive Def Tech PERC 5i RAID card w/ BBU (LSI Firmware) 
  hide details  
Reply
Maximum Dwarf
(15 items)
 
Density!
(12 items)
 
 
CPUMotherboardGraphicsRAM
i5-3570k ASUS MAXIMUS IV GENE HD7970 Gen 1 Ripjaws Z 2x8GB 2133MHz 
Hard DriveHard DriveOptical DriveCooling
1TB RE4 2x3TB WD Red LG 10x BD-R Corsair H80i w/push pull 
OSMonitorKeyboardPower
Win 7 Ultimate 3x 1920x1080 LG IPS displays. Razer Mass Effect 3 Blackwidow Ultimate Cooler Master Silent Pro M850 
CaseMouseMouse Pad
Silverstone TJ08B-E R.A.T. 7 An ergonomic one 
CPUMotherboardRAMHard Drive
i7 3770k Gigabyte Sniper M3 1155 mATX CORSAIR Vengeance 8GB (2 x 4GB) 1600MHz 1TB WD RE4 
Hard DriveHard DriveHard DriveHard Drive
2TB WD Red 2TB WD Red 4TB WD Red 4TB WD Red 
PowerCaseAudioOther
750W Seasonic Gold Fractal Node 804 5.1 Definitive Def Tech PERC 5i RAID card w/ BBU (LSI Firmware) 
  hide details  
Reply
post #7 of 8
Thread Starter 
Quote:
Originally Posted by bru_05;15204888 
Write your own function that will load your list box and call the function in the load will be an easy way to start it. From there you can change that function to grab the list from your folder and won't have to make huge code changes in the form load.

I was eager to say "I have no idea how to do this", which I didn't. But I managed to figure it out. Thanks a bunch!
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
Karnak
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x2 550 @ 3.7Ghz Gigabyte MA-770T-UD3P Gigabyte 6850 1GB G.Skill 4GB DDR3 @ 1333 
Hard DriveOSMonitorPower
WDC 640GB Windows 7 Ultimate 64bit Acer X223Wbd Antec 650W 
CaseMouse
Antec 300 Logitech MX Revolution 
  hide details  
Reply
post #8 of 8
Quote:
Originally Posted by kurt1288;15205543 
I was eager to say "I have no idea how to do this", which I didn't. But I managed to figure it out. Thanks a bunch!

Nice! I didn't want to just give you the code because the best way to learn programming is to get hands on. Once you have your way of doing it, you can search around and find out how others did similar things. Pick up a few things here and there.

Good luck and keep us posted!
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD PII 955 X4 3.8 ASRock 990FX Extreme4 Sapphire 2GB Radeon HD 6950 CORSAIR Vengeance DDR3 8GB 
OSMonitorKeyboardPower
Windows 7 64-bit Dell 24" Logitech G15 Corsair TX650 
CaseMouse
Lian Li K60 Razer Copperhead 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Visual Studio VB.NET help