Issues with bound combo box

Items in field not displaying in correct order

Page 1 of 1

2 Replies - 1665 Views - Last Post: 07 January 2010 - 11:35 PM Rate Topic: -----

#1 south73paw  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 88
  • Joined: 06-October 08

Issues with bound combo box

Posted 05 January 2010 - 12:11 AM

Hi, using VS 2010 Pro Beta and Access 2007 - I have created a database connection and a dataset through the IDE rather than writing all these lines of code manually. I have two different bound combo boxes on a form: one of the combo boxes displays values from a database field in the same order as in the database, while the other combo box mucks up the display order.

I have the following tables:

1. subjects - fields: SubjectID (PK) and SName
2. lessons - fields: numerous including LessonID (PK) and SName
3. levels - fields: YearID (PK) and Level

My 'level' combo box displays data in the same order as how I added data to the Access file. It's properties are:
* Data source: LevelsBindingSource
* Display member: Level
* Value member: YearID
* Selected value: LessonsBindingSource - Level

BUT

My 'subject' combo box displays data from the database incorrectly. The first item in the list is the last record added to the subjects table, followed by items in order, but starting from the middle of the list

Example:

Spanish
Economics
Education
History
Accounting
Biology

The properties for the 'subject' combo box are:
* Data source: SubjectsBindingSource
* Display member: SName
* Value member: SName
* Selected value: LessonsBindingSource - SName

How do I get the data in the combo box to display in the same (alphabetical) order in which data was added to the original database file?

FYI - I haven't got my head around why the 'value member' property is needed. I know it's returned by 'selected value', but I don't understand exactly what it is. I'm not sure if this affects my display order or not.

I haven't changed any other properties of the combo box as every time I try I get an error saying that the property can't be changed when it is bound to a data source.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Issues with bound combo box

#2 south73paw  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 88
  • Joined: 06-October 08

Re: Issues with bound combo box

Posted 07 January 2010 - 03:14 PM

Hi, anyone able to help me out here?

My entire code for this form so far is below:

Imports System.Data
Imports System.Data.OleDb

Public Class frmAddNewLesson

	Private Sub LessonsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Me.Validate()
		Me.LessonsBindingSource.EndEdit()
		Me.TableAdapterManager.UpdateAll(Me.LessonPlannerDataSet)

	End Sub

	Private Sub frmAddNewLesson_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'TODO: This line of code loads data into the 'LessonPlannerDataSet.units' table. You can move, or remove it, as needed.
		Me.UnitsTableAdapter.Fill(Me.LessonPlannerDataSet.units)

		'TODO: This line of code loads data into the 'LessonPlannerDataSet.subjects' table. You can move, or remove it, as needed.
		Me.SubjectsTableAdapter.Fill(Me.LessonPlannerDataSet.subjects)
		'TODO: This line of code loads data into the 'LessonPlannerDataSet.subjects' table. You can move, or remove it, as needed.
		Me.SubjectsTableAdapter.Fill(Me.LessonPlannerDataSet.subjects)
		'TODO: This line of code loads data into the 'LessonPlannerDataSet.levels' table. You can move, or remove it, as needed.
		Me.LevelsTableAdapter.Fill(Me.LessonPlannerDataSet.levels)
		'TODO: This line of code loads data into the 'LessonPlannerDataSet.lessons' table. You can move, or remove it, as needed.
		Me.LessonsTableAdapter.Fill(Me.LessonPlannerDataSet.lessons)

		SNameComboBox.SelectedItem = 0

		cboTest.SelectedItem = 0

		UNameComboBox.Visible = False

	End Sub

	Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

		Try
			Me.LessonsTableAdapter.FillBy(Me.LessonPlannerDataSet.lessons)
		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try

	End Sub

	Private Sub SNameComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SNameComboBox.SelectedIndexChanged

		UNameComboBox.Visible = True

	End Sub
End Class


As you can see most of what I've done with bound controls has been through the IDE itself rather than handcoding the data connection etc.

Any help here would be greatly appreciated!

Thanks

:-)
Was This Post Helpful? 0
  • +
  • -

#3 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Issues with bound combo box

Posted 07 January 2010 - 11:35 PM

Hi again,

If your combobox is bound, you need to perform the sort in your querry in the table adapter.

;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1