none
Strange Behavior of Combobox with DropDownList RRS feed

  • Question

  • Hello Every Body,

    I'm facing a problem when i change combo box DropDownStyle to DropDownList and click a save button the text on the combo box disappears ,Ok i tried to fix it after searching a web and found an article speaks about 'PostBack' and it must check like that

    If Not Me.IsPostBack Then
    
    End if

    but it failed to solve the issue ... this code helped me to avoid this behavior

    If cmbCategory.SelectedItem <> Nothing Then
                cmbCategory.SelectedItem.ToString()
    End If

    Really it solved this issue when i click the save button the combo box keep the text on it .......

    But when i retrieve data to this combo box it is still empty and this is my code 

      Using f6 As New AddProductForm6
    
                Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
                Me.Hide()
                
                f6.txtProductCode.Text = dr.Cells(0).Value.ToString()
                f6.txtProductName.Text = dr.Cells(1).Value.ToString()
                f6.txtStockNo.Text = dr.Cells(2).Value.ToString()
                f6.cmbCategory.Text = dr.Cells(3).Value.ToString()
                f6.txtPrice.Text = dr.Cells(4).Value.ToString()
                f6.txtSellPrice.Text = dr.Cells(5).Value.ToString()
                f6.DateTimePicker1.Value = CDate(dr.Cells(6).Value.ToString())
                f6.txtStockID.Text = dr.Cells(7).Value.ToString()
    
                f6.Update_Record.Enabled = True
                f6.Delete.Enabled = True
                f6.Save.Enabled = False
    
                If f6.ShowDialog = DialogResult.OK Then
                    f6.ShowDialog()
                    If f6.cmbCategory.SelectedItem = Nothing Then
                        f6.cmbCategory.Text = dr.Cells(3).Value.ToString()
                        'f6.cmbCategory.SelectedItem.ToString()
                    End If
                Else
                    f6.Close()
                End If
    End Using
     Every item of this DatagridView transfere to its textboxes exept this one 
    f6.cmbCategory.Text = dr.Cells(3).Value.ToString()

    Any suggestion

    Thanks in advance

     


    Regards From Amr_Aly

    Saturday, November 17, 2018 6:18 PM

All replies

  • Put a debug break on line:

      f6.cmbCategory.Text = dr.Cells(3).Value.ToString()

    and look at the value of cell 3. Is it what you expect? Is there an error? Is the next step an error?

    Do you have visual studio project set break on clr errors? If not you could have an error that vs is just skipping over and not notifying.

    Saturday, November 17, 2018 7:12 PM
  • Put a debug break on line:

      f6.cmbCategory.Text = dr.Cells(3).Value.ToString()

    and look at the value of cell 3. Is it what you expect? Is there an error? Is the next step an error?

    Do you have visual studio project set break on clr errors? If not you could have an error that vs is just skipping over and not notifying.

    Ok Mr Tommy,

    i tried a debug break on this line and no errors ,when i changed the combo box style to DropDown or to simple this behavior disappears ..... it appears only with DropDownList Style .                         Please take a look here

    Thanks


    Regards From Amr_Aly

    Sunday, November 18, 2018 8:03 AM
  • Ok Mr Tommy,

    i tried a debug break on this line and no errors ,when i changed the combo box style to DropDown or to simple this behavior disappears ..... it appears only with DropDownList Style .                         Please take a look here

    Thanks


    Regards From Amr_Aly

    Ok. Well this does not make sense:

         If f6.ShowDialog = DialogResult.OK Then
               f6.ShowDialog()

    Why would you show f6 after you close f6 dialog with ok??? 

    I don't see how that whole section is supposed to work? Or what its that if supposed to do?

    PS Are you sure your project is set to break on errors? See item 2 here.



    Sunday, November 18, 2018 11:13 AM
  • Ok Mr Tommy,

    i tried a debug break on this line and no errors ,when i changed the combo box style to DropDown or to simple this behavior disappears ..... it appears only with DropDownList Style .                         Please take a look here

    Thanks


    Regards From Amr_Aly

    Ok. Well this does not make sense:

         If f6.ShowDialog = DialogResult.OK Then
               f6.ShowDialog()

    Why would you show f6 after you close f6 dialog with ok??? 

    I don't see how that whole section is supposed to work? Or what its that if supposed to do?

    PS Are you sure your project is set to break on errors? See item 2 here.



    Hi Tommy,

    you may be misunderstanding me , My project is set to break on errors .... 

    this problem faced many people not me only when they use combobox with DropDownList style

    I changed my code that does not make sense and the problem still persist ... i can get over it by using DropDown Style or Simple Style of combobox ... When i searched after i asked my question i found in stack over flow site a question that talk about something like that and the solution was by making a class to avoid this problem but i need a simple solution or i will use the other style of the combobox

      Thanks tommy ...I'm glad that you want to help me


    Regards From Amr_Aly

    Monday, November 19, 2018 7:52 AM


  • Hi Tommy,

    you may be misunderstanding me , My project is set to break on errors .... 

    this problem faced many people not me only when they use combobox with DropDownList style

    I changed my code that does not make sense and the problem still persist ... i can get over it by using DropDown Style or Simple Style of combobox ... When i searched after i asked my question i found in stack over flow site a question that talk about something like that and the solution was by making a class to avoid this problem but i need a simple solution or i will use the other style of the combobox

      Thanks tommy ...I'm glad that you want to help me


    Regards From Amr_Aly

    Ok. LOL. 

    Well I was just trying to understand what you are trying to do exactly.

    I dont see where the problem has been isolated down to the control? All I see are problems in the code you posted that tell me the example code wont even run so I dont know how you can determine the control has a problem?

    But, no matter, I dont understand the whole situation and you do. Carry on...

    Except one more tip...  try to get the problem down to its simplest reproducible form. Then you can experiment with it better. Most times one will find the answer trying to make a simple example.

    :)


    Monday, November 19, 2018 11:25 AM
  • Thank you ver much TommyTwotrain

    Regards From Amr_Aly

    Monday, November 19, 2018 12:24 PM
  • Hi,

    Do you resolve the issue? If you resolve the issue, could you please mark the helpful as answer. it will be beneficial to other community.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 20, 2018 2:54 AM
  • Hi,

    Do you resolve the issue? If you resolve the issue, could you please mark the helpful as answer. it will be beneficial to other community.

    Best Regards,

    Alex


    Hi Mr Alex, 

    No i don't resolve it yet ..... till now i decided to use DropDown style or Simple style  


    Regards From Amr_Aly

    Tuesday, November 20, 2018 6:49 AM
  • Hi,

    After the combobox DropDownStyle property is set to dropdownlist, the text assignment value is displayed if there is a content in the content of the combobox, and no display is not displayed.

    You can try adding dr.Cells(3).Value.ToString() to f6.cmbCategory first.

    f6.cmbCategory.Items.Add(dr.Cells(3).Value.ToString())

    f6.cmbCategory.Text = dr.Cells(3).Value.ToString()


    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 20, 2018 8:14 AM
  • Hi,

    After the combobox DropDownStyle property is set to dropdownlist, the text assignment value is displayed if there is a content in the content of the combobox, and no display is not displayed.

    You can try adding dr.Cells(3).Value.ToString() to f6.cmbCategory first.

    f6.cmbCategory.Items.Add(dr.Cells(3).Value.ToString())

    f6.cmbCategory.Text = dr.Cells(3).Value.ToString()


    Best Regards,

    Alex

    It did not work also, Thanks for help Alex 

    Regards From Amr_Aly

    Tuesday, November 20, 2018 7:00 PM
  • Hi,

    After the combobox DropDownStyle property is set to dropdownlist, the text assignment value is displayed if there is a content in the content of the combobox, and no display is not displayed.



    Hi Mr Alex,

    I found that(discovered) if the combobox in DropDownList style mode and it has a text (not empty) when i populate it, it works well ........ the problem appears when it leaves empty so when i want to populate or fill it ,it still empty .... The question here is how to make it populated all time in order to fill it again when i want ................. ?

    Thanks in advance   


    Regards From Amr_Aly



    • Edited by Amr_Aly Sunday, November 25, 2018 2:11 PM
    Sunday, November 25, 2018 6:10 AM