943,645 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 8505
  • VB.NET RSS
Nov 16th, 2007
0

can not update combo box...

Expand Post »
Hi,

I have written a program that binds controls on a form to fields of a table in a Microsoft Access database.One of the controls on the form is a combo box that is binding to table called Type_T which contains one column called Type.

i need to update the combo box whith the new values when i update the table Type_T. the addition of the table going fine and i see the record updated, but the combo box remain without changes.

I have tried this code :

VB.NET Syntax (Toggle Plain Text)
  1. Me.ComboBox2.DataSource = Nothing
  2. Me.ComboBox2.DataSource = Me.DataBaseDataSet.Type_T
  3. 'Me.ComboBox2.DataSource = Me.TypeTBindingSource
  4. Me.ComboBox2.DisplayMember = "Type"
  5. Me.ComboBox2.ValueMember = "Type"

but nothing happened.

I have tried this also:
VB.NET Syntax (Toggle Plain Text)
  1. Dim bd As Binding
  2. bd = New Binding("Text", ds, "Type_T.Type")
  3. Me.ComboBox2.DataBindings.Add(bd)
there were no changes in the combo box.

in addition, this was my last attempt to update it which is to call ReFillCombo()

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub ReFillCombo()
  2. Me.ComboBox2.Items.Clear() ' Clear the items of the combobox
  3. Dim constr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\HST\My Documents\Visual Studio 2005\Projects\Invoice\Invoice\DataBase.mdb"
  4. Dim conn As New OleDb.OleDbConnection(constr)
  5. Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Type_T", conn)
  6. Dim dt As New DataTable
  7. da.Fill(dt)
  8. Me.ComboBox1.DataSource = dt
  9. Me.ComboBox1.DisplayMember = "Type"
  10. Me.ComboBox1.ValueMember = "Type"
  11. End Sub

and it gives me this error: Items collection can not be modified when the datasource property is set.

every time i have to close the application and re run it again to see the updat in the combo box.

please help me !!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokahantos is offline Offline
22 posts
since Mar 2006
Nov 19th, 2007
0

Re: can not update combo box...

Try THis:
======

Me.ComboBox1.DataSource = dt 'Can be any other table
Me.ComboBox1.DisplayMember = "Type"
Me.ComboBox1.ValueMember = "Type"
Me.ComboBox1.Refresh()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MehdiAnis is offline Offline
12 posts
since Nov 2007
Nov 19th, 2007
0

Re: can not update combo box...

I have already tried that.
nothing yet different.

i have the same problem with datagridview, dont display what i have add.


If posting the whole code here help, let me know.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokahantos is offline Offline
22 posts
since Mar 2006
Nov 19th, 2007
0

Re: can not update combo box...

check out,whether u have written checkbox function-inside the if(page.isnotpostback)
regards,,
preetham
Reputation Points: 5
Solved Threads: 1
Junior Poster in Training
preetham.saroja is offline Offline
82 posts
since Jun 2007
Nov 20th, 2007
0

Re: can not update combo box...

Hi

i found the solution ... it was in this code:
e.ComboBox2.DataSource = ds.Tables("Temp_table")

rather than:
e.ComboBox2.DataSource = ds

Thank you all for your help
i really appreciate it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokahantos is offline Offline
22 posts
since Mar 2006
Nov 30th, 2007
0

Re: can not update combo box...

can you show me what your complete code for these lines look like
Reputation Points: 10
Solved Threads: 0
Newbie Poster
swuwarrior is offline Offline
11 posts
since Nov 2007
Nov 30th, 2007
0

Re: can not update combo box...

Private Sub ReFillCombo()
Me.ComboBox2.Items.Clear() ' Clear the items of the combobox
Dim constr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\HST\My Documents\Visual Studio 2005\Projects\Invoice\Invoice\DataBase.mdb"
Dim conn As New OleDb.OleDbConnection(constr)
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Type_T", conn)
Dim dt As New DataTable
da.Fill(dt)
Me.ComboBox1.DataSource = ds.Tables("Temp_table")
Me.ComboBox1.DisplayMember = "Type"
Me.ComboBox1.ValueMember = "Type"
End Sub
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokahantos is offline Offline
22 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: login
Next Thread in VB.NET Forum Timeline: [urgent] Need Help on my VB6 game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC