How to add items in combobox at runtime when the combobox is bound to the database
-
Friday, April 20, 2012 4:21 AM
hi
my combobox is already bound to the database. if i try to add an item.it will display
an error message item collection cannot be modified.if any one have any idea about how to
do it help me.i have ask this question many times still i can't able to find a correct solution .
thanks in advance.
All Replies
-
Friday, April 20, 2012 5:39 AM
Hello,
As far as I see,a combobox cannot do both of the things together……Maybe you can use foreach to loop your datasource and call "Add" method to add one by one。
- Marked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Monday, April 23, 2012 3:46 AM
- Unmarked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Monday, April 23, 2012 3:46 AM
- Proposed As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Monday, April 23, 2012 3:46 AM
-
Sunday, April 22, 2012 6:43 AM
Hi
Did you mean this way:
Dim cmd As SqlCommand Dim dr As SqlDataReader con.Open() Dim sql As String = "SELECT * from table" cmd = New SqlCommand(sql, con) dr = cmd.ExecuteReader() cbo1.Items.Add("new item") If dr.HasRows Then While dr.Read() cbo1.Items.Add(dr(0)) End While End IfIts a code to fill combobox . and the line below is aimed to add item independantly of binded datacbo1.Items.Add("new item")Post your code if its posisble to se how we can help you
Regards
Best Regards...Please mark as answer if my post is helpful http://yosr-jemili.blogspot.com
- Edited by YosrJ Sunday, April 22, 2012 6:44 AM
- Proposed As Answer by ProgrammingVolunteerMVP Sunday, April 22, 2012 8:15 AM
- Marked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Tuesday, May 01, 2012 2:19 AM



