Code Q & A
  • index
  • Java
  • python
  • javascript
No Result
View All Result
Code Q & A
  • index
  • Java
  • python
  • javascript
No Result
View All Result
Code Q & A
No Result
View All Result

ComboBox Selection

06/23/2022
in combobox, VB.net
Reading Time: 1 min read

I am having trouble using a bindingsource to select an item in a combobox.
I populate the combobox no problem, the items are listed. I double checked that my binding source contains information.

Combobox has a displaymember (text) and valuemember(integer)

my bindingsource contains the valuemember.

How do i bind the combobox to bindingsource so it shows the correct displaymemeber based on the valuemember stored in bindingsource.

this is what i have tried

cboAccessLevel.SelectedValue = EditMembershipBindingSource("accesslevelid")

I am using vb.net

here is bindingcode

        strSQL = "select * from memberships where name = " & "'" & MembershipName & "'"

        Using Connection As New SqlConnection(ProgramSQLConnection)
            Connection.Open()
            Dim Command As New SqlClient.SqlCommand(strSQL, Connection)
            Dim MyAdapter As SqlDataAdapter = New SqlDataAdapter
            MyAdapter.SelectCommand = Command
            dtSpecificMembership = New DataTable
            MyAdapter.Fill(dtSpecificMembership)
            EditMembershipBindingSource.DataSource = dtSpecificMembership
            Connection.Close()
        End Using

cboAccessLevel.DataTextField = displayMember
cboAccessLevel.DataValueField = valuemember

If I understand your question correctly ...

This is what worked for me:

cboAccessLevel.DataBindings.Add("Selectedvalue", EditMembershipBindingSource, "accesslevelid")

Hai add your BindingSource with Onedataset and TableAdapter and using Combobox Use Bound data items options tick and select your datasource and choose your bindingsource and value member and display member

Tags: comboboxvb.net
ShareTweetPin

Related Posts

.net

Why Isn't My .Net Object Serializable?

I've got a 'MyDataTable' class that inherits from System.Data.DataTable I've implemented ISerializable in my class and have a 'Public Overrides...

.net

Trying to serialize a list of objects fails

I am trying to save a list of objects to file but getting an exception thrown in the process. This...

c#

How do I have an enum bound combobox with custom string formatting for enum values?

In the post Enum HowNice { ReallyNice, SortOfNice, NotNice } And then, you call a function GetDescription, using syntax like:...

entity-framework

Entity Framework: "The relationship could not be changed because one or more of the foreign-key properties is non-nullable" when adding child objects

The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When...

Next Post

Exception when setting SelectedValue on CF Combobox

Hot tags

.htaccess .net Algorithm amazon-web-services android Apache c# css c语言 django django-models docker google-app-engine google-cloud-platform hadoop Hive html ios java javascript kubernetes linux macos maven mysql node.js php postgresql python python-2-7 Python 3.X R ruby ruby-on-rails spring SQL SQL SERVER svn TensorFlow ubuntu windows xcode 爬虫 算法 编程语言

    © 2022 Websitedic.com.

    No Result
    View All Result
    • index
    • Java
    • python
    • javascript