Click here to Skip to main content
15,886,693 members
Home / Discussions / C#
   

C#

 
GeneralRe: connectionstring to sqlexpress 2005 Pin
Hiren solanki19-Jan-11 2:25
Hiren solanki19-Jan-11 2:25 
GeneralRe: connectionstring to sqlexpress 2005 Pin
arkiboys19-Jan-11 3:08
arkiboys19-Jan-11 3:08 
AnswerRe: connectionstring to sqlexpress 2005 Pin
Dan Mos19-Jan-11 2:44
Dan Mos19-Jan-11 2:44 
GeneralRe: connectionstring to sqlexpress 2005 Pin
Henry Minute19-Jan-11 7:48
Henry Minute19-Jan-11 7:48 
GeneralRe: connectionstring to sqlexpress 2005 Pin
Dan Mos19-Jan-11 7:55
Dan Mos19-Jan-11 7:55 
GeneralRe: connectionstring to sqlexpress 2005 Pin
arkiboys19-Jan-11 11:23
arkiboys19-Jan-11 11:23 
AnswerRe: connectionstring to sqlexpress 2005 Pin
jschell19-Jan-11 8:40
jschell19-Jan-11 8:40 
QuestionDataBindingComplete on ComboBox? Pin
Dewald19-Jan-11 0:36
Dewald19-Jan-11 0:36 
Hi all, I'm experiencing something odd (well, to me at least but I'm sure there is a good explanation for it). I have a ComboBox on my form which I populate as follows:
using (SqlCommand myCommand = new SqlCommand("SELECT Value, Description FROM ...", myConnection))
{
   using (SqlDataReader myReader = myCommand.ExecuteReader())
   {
      DataSet myDataSet = new DataSet();
      DataTable myDataTable = new DataTable();
      myDataSet.Tables.Add(myDataTable);
      myDataSet.Load(myReader, LoadOption.PreserveChanges, myDataSource.Tables[0]);
      myComboBox.DataSource = myDataSource.Tables[0];
      myComboBox.DisplayMember = "Description";
      myComboBox.ValueMember = "Value";
   }
}


This is the way I've always used to populate ComboBoxes from a DB. If it's wrong, please let me know so I can start doing it differently, although it has worked for me so far.

The problem I'm getting is that I'm trying to set the SelectedValue of the ComboBox immediately after the above block of code with something like
myComboBox.SelectedValue = myDefaultValue; //myDefaultValue is of course a value that I know will be in the list returned by the original query

but it does nothing. When I step through the code I notice that by the time the above line executes the value of myComboBox.Items.Count is still 0 so it appears as if the binding has not finished yet, but the ComboBox does not have a DataBindingComplete() event.

Can anyone tell me of a way to make sure that the ComboBox is bound to the DB before I try to change the SelectedValue explicitly?
AnswerRe: DataBindingComplete on ComboBox? Pin
Dan Mos19-Jan-11 1:04
Dan Mos19-Jan-11 1:04 
GeneralRe: DataBindingComplete on ComboBox? Pin
Dewald19-Jan-11 3:34
Dewald19-Jan-11 3:34 
AnswerRe: DataBindingComplete on ComboBox? [modified] Pin
RaviRanjanKr19-Jan-11 1:30
professionalRaviRanjanKr19-Jan-11 1:30 
AnswerRe: DataBindingComplete on ComboBox? Pin
ToddHileHoffer19-Jan-11 2:44
ToddHileHoffer19-Jan-11 2:44 
GeneralRe: DataBindingComplete on ComboBox? Pin
Dewald19-Jan-11 3:47
Dewald19-Jan-11 3:47 
GeneralRe: DataBindingComplete on ComboBox? Pin
ToddHileHoffer19-Jan-11 4:38
ToddHileHoffer19-Jan-11 4:38 
AnswerRe: DataBindingComplete on ComboBox? Pin
_Erik_19-Jan-11 3:28
_Erik_19-Jan-11 3:28 
GeneralRe: DataBindingComplete on ComboBox? Pin
Dewald19-Jan-11 4:00
Dewald19-Jan-11 4:00 
GeneralRe: DataBindingComplete on ComboBox? Pin
_Erik_19-Jan-11 5:58
_Erik_19-Jan-11 5:58 
AnswerRe: DataBindingComplete on ComboBox? Pin
MumbleB19-Jan-11 6:24
MumbleB19-Jan-11 6:24 
GeneralRe: DataBindingComplete on ComboBox? Pin
Dewald19-Jan-11 20:40
Dewald19-Jan-11 20:40 
Questionhow should i word this... and better...how should i do it? Pin
jwalker34318-Jan-11 17:01
jwalker34318-Jan-11 17:01 
AnswerRe: how should i word this... and better...how should i do it? Pin
PIEBALDconsult18-Jan-11 18:19
mvePIEBALDconsult18-Jan-11 18:19 
GeneralRe: how should i word this... and better...how should i do it? Pin
jwalker34319-Jan-11 1:59
jwalker34319-Jan-11 1:59 
AnswerRe: how should i word this... and better...how should i do it? Pin
#realJSOP18-Jan-11 23:47
mve#realJSOP18-Jan-11 23:47 
GeneralRe: how should i word this... and better...how should i do it? Pin
jwalker34319-Jan-11 2:05
jwalker34319-Jan-11 2:05 
GeneralRe: how should i word this... and better...how should i do it? Pin
#realJSOP19-Jan-11 2:10
mve#realJSOP19-Jan-11 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.