last item in combobox

  • Thread starter Thread starter Graeme
  • Start date Start date
G

Graeme

Hi

How do I check to see if last item in list/combobox has been selected? If I
could count items in box it would help! Maybe snippet for both please?

Thanks
Graeme
 
if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
MessageBox.Show("yep");
 
One of the simple Way is given below ... just see if works for yo

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'The connection string Refers to Northwind database and the Table is customers
Dim intItemCount As Intege
Tr
SqlDataAdapter1.Fill(DataSet1
ComboBox1.DataSource = DataSet1.Tables(0
intItemCount = DataSet1.Tables(0).Rows.Coun
'****************
'If the Combobox has no datasource but you have added the Items through code then
'intItemCount = ComboBox1.Items.Coun
'**************

ComboBox1.DisplayMember = "CustomerID
ComboBox1.ValueMember = "ContactName
'Code to Verify if the last Item is selecte
'If DataSet1.Tables(0).Rows(intItemCount - 1).Item("ContactName") = ComboBox1.Text The
' MessageBox.Show("Last item selected"
'End I

Catch exc As Exceptio
MessageBox.Show(exc.Message
End Tr
End Su


The Other more sophisticated Way is the get the selected index and the cont through the use of Binding context
 
Back
Top