ListBox, ComboBox Bug???

S

samoore33

I am trying to dynamically add items to a listbox or combobox. The
items add to either, but when I look through those items, there is
nothing there. If I choose an item, it shows up.

Not sure why, but the items are not visible in the listbox or combobox
until one of the items has been chosen. This of course is not good,
since someone can not see the items they need to choose from.

Any help would be appreciated.

Scott Moore
 
S

samoore33

Duh, brainfart! I acquired this PC from a previous programmer, he had
not updated to 1.1 Framework, could that be the problem. The form I am
working with may have been written on the 2.0 Framework.

myDataSet.ReadXML("this.xml")

The dataset has three tables in it. I use the foundRows DataRow to get
the id to match up the items in the third table.

'Used to searchthrough the dataset
Dim t As DataTable
t = myDataSet.Tables("State")
Dim strExpr = "id = '" &
returnItems.SubItems.Item(count).Text & "'"
Dim foundRows() As DataRow
'returns the datarows that were found in the search
foundRows = t.Select(strExpr)

Dim taxRow() As DataRow 'creates the tax row to be looped through to
populate the combobox

'Searches through the tax tabel of the dataset
taxRow = myDataSet.Tables("Tax").Select("Taxes_Id =
'" & foundRows(0)(2) & "'")

'Populates the combo box for updating purposes
If taxRow.Length > 1 Then
Dim cnt As Integer
For cnt = 0 To taxRow.Length - 1
Dim k As Integer
For k = 2 To 2
'I only need the second row out of the
datarow

cmbTest.Items.Add((taxRow(count)(k)).ToString())
Next
Next
End If
 
R

rowe_newsgroups

Well, nothing I see would make the combobox's contents "invisible."
Does a certain event fire this code? If you could, please post that
code too (everything from sub to end sub), I have a feeling you might
be calling this code in the wrong event. Also your below code shouldn't
need the inner for next loop - so you could change this:
If taxRow.Length > 1 Then
Dim cnt As Integer
For cnt = 0 To taxRow.Length - 1
Dim k As Integer
For k = 2 To 2
'I only need the second row out of the datarow
cmbTest.Items.Add((taxRow(count)(k)).ToString())
Next
Next
End If

to this:

If taxRow.Length > 1 Then
Dim cnt As Integer
For cnt = 0 To taxRow.Length - 1
'I only need the second row out of the datarow
cmbTest.Items.Add((taxRow(count)(2)).ToString())
Next
End If

Thanks,

Seth Rowe
 
S

samoore33

The event that calls this is when the user selects an item out of the
listview. Code is below:

Private Sub lsvTest_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lsvTest.SelectedIndexChanged

'Clears the items in the combbo box
cmbTest.Items.Clear()

Dim TaxData As CRTTaxDataSet = New CRTTaxDataSet

'Reads the xml into the dataset
myDataSet.ReadXml("this.xml")

'dim variables to be used
Dim returnItems As ListViewItem =
Me.GetSelectedListViewItem(lsvTest.Items)
Dim item As String
Dim count As Integer

'loops through the item that has been selected to populate the
text boxes
For count = 0 To returnItems.SubItems.Count - 1
Select Case count
'Populates the corresponding textbox and old value
textbox for comparison for updating
Case 1
cboState.SelectedItem =
returnItems.SubItems.Item(count).Text

'Used to searchthrough the dataset
Dim t As DataTable
t = myDataSet.Tables("State")
Dim strExpr = "id = '" &
returnItems.SubItems.Item(count).Text & "'"
Dim foundRows() As DataRow
'returns the datarows that were found in the search
foundRows = t.Select(strExpr)

Dim taxRow() As DataRow 'creates the tax row to be
looped through to populate the combobox

'Searches through the tax tabel of the dataset
taxRow = myDataSet.Tables("Tax").Select("Taxes_Id =
'" & foundRows(0)(2) & "'", "Value")

'Populates the combo box for updating purposes
Dim cnt As Integer
For cnt = 0 To taxRow.Length - 1
Dim k As Integer
For k = 0 To 2
If k = 2 Then

cmbTest.Items.Add((taxRow(cnt)(k)).ToString())
End If
Next
Next
End Select
Next

'Clears the dataset
myDataSet.Clear()

End Sub
 
S

samoore33

Drawmod is set to Normal. I really think that it is a problem with the
..Net Framework. It works on other peoples computers, just not mine. I
appreciate the help.

Scott Moore
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top