Click here to Skip to main content
15,893,564 members
Home / Discussions / C#
   

C#

 
GeneralRe: p/invoke _stat Pin
DanielWehrle20-Jan-11 20:29
DanielWehrle20-Jan-11 20:29 
GeneralRe: p/invoke _stat Pin
Richard MacCutchan20-Jan-11 21:31
mveRichard MacCutchan20-Jan-11 21:31 
QuestionProgramming Scanner Hardware Pin
RobScripta19-Jan-11 4:43
professionalRobScripta19-Jan-11 4:43 
AnswerRe: Programming Scanner Hardware Pin
Richard MacCutchan19-Jan-11 5:15
mveRichard MacCutchan19-Jan-11 5:15 
GeneralRe: Programming Scanner Hardware Pin
RobScripta19-Jan-11 5:27
professionalRobScripta19-Jan-11 5:27 
GeneralRe: Programming Scanner Hardware Pin
Richard MacCutchan19-Jan-11 5:44
mveRichard MacCutchan19-Jan-11 5:44 
GeneralRe: Programming Scanner Hardware Pin
RobScripta20-Jan-11 1:06
professionalRobScripta20-Jan-11 1:06 
GeneralRe: Programming Scanner Hardware Pin
Richard MacCutchan20-Jan-11 1:39
mveRichard MacCutchan20-Jan-11 1:39 
QuestionResourse file and axWindowsMediaPlayer(C#) Pin
Maximys19-Jan-11 2:45
Maximys19-Jan-11 2:45 
AnswerRe: Resourse file and axWindowsMediaPlayer(C#) Pin
RaviRanjanKr20-Jan-11 17:33
professionalRaviRanjanKr20-Jan-11 17:33 
Questionconnectionstring to sqlexpress 2005 Pin
arkiboys19-Jan-11 1:53
arkiboys19-Jan-11 1:53 
AnswerRe: connectionstring to sqlexpress 2005 Pin
Hiren solanki19-Jan-11 2:05
Hiren solanki19-Jan-11 2:05 
GeneralRe: connectionstring to sqlexpress 2005 Pin
arkiboys19-Jan-11 2:14
arkiboys19-Jan-11 2:14 
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 

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.