none
How to get last index of combobox

    Question

  • Hi all,

    how could i get the last index of the item being selected by using ComboBox during the items being added to the combo box control?

    since the last index of the combo box is depends on variance number, it was hard to get the last index of the combo box item being selected by default.

    Wednesday, December 21, 2005 8:12 AM

Answers

  • I can't quite understand what you're trying to say. Do you simply need the count of the combobox items? That's combobox.Items.Count. Last index is combobox.Items.Count - 1.
    Wednesday, December 21, 2005 8:20 AM

All replies

  • I can't quite understand what you're trying to say. Do you simply need the count of the combobox items? That's combobox.Items.Count. Last index is combobox.Items.Count - 1.
    Wednesday, December 21, 2005 8:20 AM
  • thanks for your info. It helps.
    Wednesday, December 21, 2005 8:25 AM
  • How is about to get the specific index from a combo box when we select the value from the combo box. I am using visual c# for window base application.

    Best regards,

     

    Thursday, January 12, 2006 8:16 AM
  • Get the index of an object with ComboBox.Items.IndexOf. Get the selected items with ComboBox.SelectedIndex or ComboBox.SelectedItem.
    Thursday, January 12, 2006 8:55 AM
  • Thank for your fast reply.
    Maybe I have written the unclear question. The combo box that I want to get the index is in a datagrid. So that I cannot use the property selectedIndex or selectedItem of datagrid combobox.

    I am using visual studio 2005 with and I want to build the winform application.

    Best regards,

    Thursday, January 12, 2006 9:33 AM
  • I personally have no experience doing that. Can't you reach the combobox inside the datagrid and retrieve the selecteditem in the way that I proposed?
    Thursday, January 12, 2006 10:46 AM
  • I am trying to explain you the way I am doing. I want to make an invoice which made from datagrid.

    I have 6 columns in my datagrid which one is hidden. The first column of datagrid holds a combo box that contains product code (displaymember) and productname (valuemember). I have another hidden combo box which contains minOrder(displaymember) and unitprice (valuemember). the second and the rest column of datagrid holds a textbox per each. All data in the combo boxs are retrieved from database.

    When user select the productcode from combo box I want to auto fill all the text box in the same row which get from the selected value combo box. For example if I have some data in my database:

    ProductCode   ProductName   MinOrder   Unitprice
    Pro001             Product01                       2         10.00
    Pro002             Product02                       1          20.00

    When my user select the product Pro001 from productcode combo box I want to auto fill the rest of the text box in the same row as

    ProductCode  Product Name Quantity   Unit Price
    Pro001            Product01                   2           10.00

    Best regards, 

     

    Thursday, January 12, 2006 11:17 AM
  • hello ,

     I am new to Vb.net. facing some problem related to combo box.

     scenario is : how to take next value of selected value from combo box like we want to    take value of (selectedindex +1 )
     I am trying to do combobox.items.item(combobox.selectedindex + 1).
    but it is not working.

     plz help....

      thanks...


     

     

     

     

     

    Tuesday, April 11, 2006 7:54 PM
  • hello.

    I am new to Vb.net. facing some problem related to combo box.

     scenario is : how to take next value of selected value from combo box like we want to    take value of (selectedindex +1 )
     I am trying to do combobox.items.item(combobox.selectedindex + 1).
    but it is not working.

     plz help....

      thanks...

    Thursday, April 13, 2006 4:14 PM
  • Hi mate.

    I had exactly the same problem for my A2 coursework that i am doing at the moment and seen as though i just solved it, i thought i'd help you out.

    Dim SelectedIndexcbo As Integer

    cboComboBox.SelectedIndex = 0

    SelectedIndexcbo = SelectedIndexcbo + 1

    cboComboBox.SelectedIndex = SelectedIndexcbo

    This will select the next item in the combo then you simple display it as it is now selected.

    I hope this helped.

    Wednesday, April 19, 2006 1:23 PM
  •  

    Hi buddy ,

    Thanks for reply.

    My problem is little & simple , though i am new to VB.net so facing this problem. 

    actually i can take value of current index by combo.selectedindex property & adding 1 to this will give next index of combo and I want value of combo box at that particular index.

    like i was tring to do , 

    dim nextIndex as integer

     nextIndex = combo.selectedIndex +1

    value = combo.items.item(nextIndex )

    but It is showing error :( , Plz help if u know.

    Rgds.

     

    Wednesday, April 19, 2006 7:11 PM
  • How are you adding the data to the combo box?

    Try this little program: Just copy and past the code.

    'CREATE A BUTTON CALLED 'Button1'

    'CREATE A LABEL CALLED 'Label1'

    'CREATE A COMBO BOX CALLED 'ComboBox1'

    'CREATE A TEXTBOX CALLED 'TextBox1'

    'ADD THIS CODE TO THE BUTTON CLICK EVENT

    Dim SelectedIndexcbo, MaxIndexValueComboBox As Integer

    Dim NewValue As String

    MaxIndexValueComboBox = (ComboBox1.Items.Count - 1) 'GETS THE MAXIMUM INDEX DEPENDING ON THE AMOUNT OF DATA THAT'S IN THE COMBO BOX

    SelectedIndexcbo = MaxIndexValueComboBox + 1 'ADDS 1 TO THE CURRENT MAXIMUM INDEX.

    NewValue = TextBox1.Text 'THE VALUE THAT IS GOING TO BE ADDED TO THE COMBO BOX.

    ComboBox1.Items.Insert(SelectedIndexcbo, NewValue) 'ADDS THE VALUE THAT IS IN THE TEXT BOX.

    ComboBox1.SelectedIndex = SelectedIndexcbo 'SELECTS THE VALUE THAT HAS JUST BEEN ADDED.

    Label1.Text = ComboBox1.SelectedItem 'THIS LABELS JUST DISPLAYS THE ITEM SELECTED IN THE COMBO BOX.

    If the way you add the data to teh combo box is similar to the program above then i might be able to find a solution around the problem.

    Thursday, April 20, 2006 1:56 PM
  • No dude , May be i am not able to convey my problem to you , I dont want to add value in combo box . i just want to reterieve value from combo box at any particular index , eg. I want value from combo box at index 6 .

    Thanks lot for ur time.

     

    Thursday, April 20, 2006 4:51 PM
  • dim lastitem as integer = 0

     

    lastitem = combobox1.items.count

     

    me.combobox1.selectedindex = lastitem -1

     

    This worked for me

    • Proposed as answer by Zakscream Tuesday, May 24, 2011 9:23 PM
    Monday, April 14, 2008 11:22 PM
  • Thank you alot.Ive been looking for this code for a while. ITS VERY USEFUL.
    Tuesday, May 24, 2011 9:25 PM