http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
Support said:
Hi All,
I am working in VB.NET.
I have a data bound control (combobox) which I want to fill with a certain
field of my table from database ( SQL as backend).
First off, is this a desktop application or a web application? If it's a
desktop application, then your control won't actually be 'bound' to the
data.
The issue is, I want these values to fill the combo at the index specified
by me, ie, not the usual 0,1,2.... by default.
Use the .Insert Method as opposed to the Add method to stick them somewhere
other than the beginning. In order to do this, you won't be able to use a
DataTable and the traditional DisplayMember, ValueMember approach, you are
going to have to use the dataReader or at least, if you use a DataTable,
iterate through it using Insert where applicable. Insert takes two
parameters, the index's position where you want it to appear and the item
itself. So, if you wanted to start filling it at index 6
//Doing it with a reader
int i = 6;
while rdr.Read(){
comboBox1.Items.Insert(i, rdr.GetString[0]);
i++;
}
//Doing it with a datatable, note you can't use the traditional
DisplayMember, ValueMember approach.
int i = 6;
foreach(DataRow dro in myDataSet.Tables[TableIndex].Rows){
comboBox1.Iterms.Insert(i, dro[0].ToString());
i++;
}
Also, not dataset, but I am
Good, considering what you are doing, it's the best way. If you don't need
a datatable for exclusive binding reasons and you aren't going to send it
back, you don't need to take the overhead hit associated with a datatable
Can anyone send me the sample code for the same?
See Above. Let me know if you have any questions
For documentation on Insert vs. add
http://msdn.microsoft.com/library/d...wsformscomboboxobjectcollectionclasstopic.asp
--
W.G. Ryan, eMVP
http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/