Blank Row on databound combobox

8 posts, 0 answers
  1. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 27 Jan 2010 Link to this post

    How can I have my combobox display nothing when my form loads?  Currently when it loads it shows an item from the table it is bound too.  I want the combobox to be blank/empty then the user can select what to pick. Currently there is only 1 item in the combobox.  Does that have any effect?   I tried to edit the combo and add a blank item but it is in the drop down but not selected.

    Thank You
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 Jan 2010 Link to this post

    Hello jerry,

    Thank you for your question. You simply need to set the SelectedIndex of your combo to -1 in the Form.Shown event. Please write again if you have other questions.

    Sincerely yours,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 28 Jan 2010 Link to this post

    Victor,
    Thank you for your quick response.  I tried that and it still didn't work.
    This is my code
    DataTable dt = new DataTable(); 
    dt = ds.Tables[0]; 
    cmbPrj.DisplayMember = "project"
    cmbPrj.ValueMember = "id"
    cmbPrj.DataSource = dt; 
    cmbPrj.SelectedIndex = -1; 
    But this still shows up with the value returned from my databinding and not the blank text RadComboBoxItem I added through the control.

    Thank You



  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 Jan 2010 Link to this post

    Hi jerry,

    Thank you for your question. Are you executing this code in the Form.Shown event handler? I am looking forward to your reply.

    Greetings,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 28 Jan 2010 Link to this post

    Victor,
    That was it.  I had it in a different event.  I thought I double checked that.

    Thank you so much

  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Jan 2010 Link to this post

    Hello jerry,

    No problem, you only have to set SelectedIndex to -1 in Form.Shown, the other code can stay where it is. If you have more questions we are ready to assist you.

    Greetings,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 29 Jan 2010 Link to this post

    Victor,
    I ran into another problem with the control we are discussing in this thread. 
    I created the SelectedIndexChanged event for that combobox.  When the user changes this combo I need to save the value into a global variable.  My problem is when I load my app and bind my data to that combo the SelectedIndexChanged event fires for each row.  When I set SelectedIndex to -1 in Form.Shown it fires the event again then I get a "Object reference not set to an instance of an object".  I hit "OK" then my app closes.  If I comment out SelectedIndex to -1 in Form.Shown I don't get the error.  I'm not sure why i'm having a difficult time creating a combobox and store it's value. 

    Thank you for any help

    Jerry
  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 01 Feb 2010 Link to this post

    Hi jerry,

    Please post the code that is causing you trouble. This way I will able to provide a specific answer. If possible please send a sample application which reproduces the exception. I am looking forward to your reply.

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WinForms is Visual Studio 2017 Ready