Question[Help]Refreshing ComboBox[Solved]

Posts 111 of 11 · Page 1 of 1
[Help]Refreshing ComboBox[Solved]
nextgen1 i promise its going to be my last topic for today. please dont delete

ok so how do i refresh a comx with the options still there.

the long way:
clear the comx1
and add the items back in again.

is there a simpler methodÉ
comx.items.clear()
Quote Originally Posted by Obama View Post
comx.items.clear()
but that will clear all the options.
All the Refresh method of any control does is redraw it on-screen. It doesn't do anything else. If the binding hasn't been updated then redrawing it will have no effect.


Try

Code:
Form1_Load(Nothing, Nothing)
or


Code:
'refresh the datasource
combobox.datasource=?datasource
'select the new field from the table to populate the combobox with
combobox.displaymember = "New Display Member"
'redraw the combobox to reflect the values
combobox.invalidate()


Obama / Drake = Google King

Obama = (to an extent) right

The Combo-Box isn't actually Database bound (though it should be).

And I will never delete a post where someone needs help.

The Tab One was deleted for one reason or the other, probably for not using the proper rules of the section as posted.

Your best bet is to use access and create a (mdb) access Database, and Bind the database to the combo box, when you do that, all changes to the combo-box will auto refresh, and auto save.

I recommend this option for just about every item on a form that will have data the constantly is changing.

Id you need help creating and accessing a database, Im around

(note to in combo-box, there is a disable smiles for this post feature, great when writing code )
Quote Originally Posted by ppl2pass View Post
nextgen1 i promise its going to be my last topic for today. please dont delete

ok so how do i refresh a combo-box with the options still there.

the long way:
clear the comx1
and add the items back in again.

is there a simpler methodÉ
Yes, you can do it by saving the contents of the combo-box to a file. Clear the items and then reload.

Here's what you need to do:

Create a sub that will save and clear the items of the combo-box:
[php]Sub SaveAndClear()
Dim finalstr As String = ""
For Each n As String In Combo-Box1.Items
finalstr += n & vbCrLf
Next
My.Computer.FileSystem.WriteAllText(My.Computer.Fi leSystem.SpecialDirectories.MyDocuments & "\temp.xxx", finalstr, False)
Combo-Box1.Items.Clear()
End Sub[/php]

Then create a sub to reload the items:
[php]Sub reload()
If My.Computer.FileSystem.FileExists(My.Computer.File System.SpecialDirectories.MyDocuments & "\temp.xxx") Then
Dim n As String = My.Computer.FileSystem.ReadAllText(My.Computer.Fil eSystem.SpecialDirectories.MyDocuments & "\temp.xxx")
Dim x() As String = n.Split(ChrW(10))
For Each z As String In x
If Not z = vbNullString Then
Combo-Box1.Items.Add(z.Trim)
End If
Next
End If
End Sub[/php]

Finally call the subs as required:
For example I call them through buttons:
[php]Private Sub refresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveAndClear()
End Sub
Private Sub ReloadItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadItems.Click
reload()
End Sub[/php]

I hope this helps !!
Quote Originally Posted by MJLover View Post
Yes, you can do it by saving the contents of the combo-box to a file. Clear the items and then reload.

Here's what you need to do:

Create a sub that will save and clear the items of the combo-box:
[php]Sub SaveAndClear()
Dim finalstr As String = ""
For Each n As String In Combo-Box1.Items
finalstr += n & vbCrLf
Next
My.Computer.FileSystem.WriteAllText(My.Computer.Fi leSystem.SpecialDirectories.MyDocuments & "\temp.xxx", finalstr, False)
Combo-Box1.Items.Clear()
End Sub[/php]

Then create a sub to reload the items:
[php]Sub reload()
If My.Computer.FileSystem.FileExists(My.Computer.File System.SpecialDirectories.MyDocuments & "\temp.xxx") Then
Dim n As String = My.Computer.FileSystem.ReadAllText(My.Computer.Fil eSystem.SpecialDirectories.MyDocuments & "\temp.xxx")
Dim x() As String = n.Split(ChrW(10))
For Each z As String In x
If Not z = vbNullString Then
Combo-Box1.Items.Add(z.Trim)
End If
Next
End If
End Sub[/php]

Finally call the subs as required:
For example I call them through buttons:
[php]Private Sub refresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveAndClear()
End Sub
Private Sub ReloadItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadItems.Click
reload()
End Sub[/php]

I hope this helps !!
Agreed, but a bound database is still optimal, especially in design
Obama got banned 14,000 posts >.< sry off topic
combo box1.items.refresh()

BAM!!!
Not the same thing mnpeep, everyone here knows that

That method will refresh with current changes in memory, the OP want's to re-institute original data on refresh, which is why a form of database was suggested, it can update dynamically.
Posts 111 of 11 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?