Results 1 to 4 of 4

Thread: Btn Click

  1. #1
    Fanatic Member
    Join Date
    Feb 09
    Posts
    818

    Btn Click

    Hi,

    I have the following code;

    Code:
    Private Sub BtnChk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChk.Click
    
            'TODO: This line of code loads data into the 'ProductDetails.QryProductDetails' table. You can move, or remove it, as needed.
            Me.QryProductDetailsTableAdapter.Fill(Me.ProductDetails.QryProductDetails, TxtTruckTyp.Text, TxtModel.Text, TxtCategory.Text)
    
    
            Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
            CmbTruckTyp.SelectedIndex = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
    
    
        End Sub
    At run time, I click the button and it works ok. Th ereason I inserted the code in BOLD is to refresh the combo box (CmbTruckTyp) and retain the selectedIndex by reading it again from TxtTruckTyp.

    Reason why I am doing this is because at run time if I do multiple selection from the combo box the value keep duplicating itself in the dropdownlist and I wanted to avoid that.

    The problem am facing now is no duplication, however, at when I click the button the cmbTruckTyp becomes blank until you select again. ie.,

    Code:
    CmbTruckTyp.SelectedIndex = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
    doesnt take effect..

    Any help please

    thanks

  2. #2
    Addicted Member
    Join Date
    Sep 08
    Location
    Reading, UK
    Posts
    159

    Re: Btn Click

    Hi Dr223

    CmbTruckTyp.SelectedIndex relates to the Actual position of each item. This will be an integer

    imagine it like

    index Item
    0 I1
    1 I2
    2 I3
    3 I4

    i think you want CmbTruckTyp.SelectedItem

    Hope this helps

    Ian

    Ian

  3. #3
    Fanatic Member
    Join Date
    Feb 09
    Posts
    818

    Re: Btn Click

    Ok Tried;

    Code:
       Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
       CmbTruckTyp.SelectedItem = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
    Now, it refreshes the combo box but doesnt have the selecteditem prior to the refresh, instead it selects the top value of the dropdownlist.

    Therefore, for test purposes I removed...

    Code:
    CmbTruckTyp.SelectedItem = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
    I noticed that when the combo box is refreshed TxtTruckTyp.Text is then set to BLANK, WHY? So then I tried to remove ;

    Code:
     Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
    Now, the TxtTruckTyp.Text retains the selecteditem of the CmbTruckTyp.

    Therefore, could the problem be

    Code:
     Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
    and if so why will it affect the textbox while it should only be refreshing the combo box?

    Thanks

  4. #4
    Addicted Member
    Join Date
    Sep 08
    Location
    Reading, UK
    Posts
    159

    Re: Btn Click

    when you fill a combo box it will make selections and if you have code in CmbTruckTyp.selectedindexchanged or any of those it will run that code

    when you bind data to a combox i find it necessary to have a boolean called something like initilising. make it true before you bind it and then false when its bound, then in the CmbTruckTyp.anythingchanged you'll want something like

    Code:
    if initilising = true then exit sub
    this will stop code being run before you want it to

    Ian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •