Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:24:58+00:00 2026-06-06T19:24:58+00:00

I have a ListBox (LB) with a DataTable (DT) DataSource in the Form Class

  • 0

I have a ListBox (LB) with a DataTable (DT) DataSource in the Form Class globally populated in the Form_Load event.

Private Sub frmEditPresets_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    DT.Columns.Add("DisplayText")
    DT.Columns.Add("PresetID")
    For Each TSI As ToolStripItem In Presets.DropDownItems
        If TSI.Name.IndexOf("preset_") > -1 Then
            DT.Rows.Add(TSI.Text, TSI.Name)
        End If
    Next
    LB.DataSource = DT
    LB.DisplayMember = "DisplayText"
End Sub

When I use my Rename button. It updates the menu item and the Data Source but the Listbox doesn’t refresh until I click another item in the listbox.

Rename code:

Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click
    Dim R As DataRowView = LB.SelectedItem
    Dim S As String = InputBox("Preset Name", "Rename", R("DisplayText"))
    If S.Trim.Length = 0 Then Exit Sub
    If Presets.DropDownItems.ContainsKey(R("PresetID").ToString) Then
        Presets.DropDownItems(R("PresetID").ToString).Text = S
    End If
    R("DisplayText") = S
End Sub

I’m sure this is a simple question with a simple answer but I can’t seem to figure it out. I’ve tried Refresh(). I’ve tried setting the DataSource again. I read this StackOverflow question Winforms listbox not updating when bound data changes but ResetBindings() doesn’t seem to be an available method in this context.

*Edit. I gave Steve credit for the answer as he mentioned BindingContext. Although, that led me to find BindingContext(DT).EndCurrentEdit() which updated my LB display and maintained the selection.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:24:59+00:00Added an answer on June 6, 2026 at 7:24 pm

    Tried with this, and it works…..

    Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click  
        Dim R As DataRowView = LB.SelectedItem  
        Dim S As String = InputBox("Preset Name", "Rename", R("DisplayText"))  
        If S.Trim.Length = 0 Then Exit Sub  
        If Presets.DropDownItems.ContainsKey(R("PresetID").ToString) Then  
            Presets.DropDownItems(R("PresetID").ToString).Text = S  
        End If  
        R("DisplayText") = S  
        BindingContext(DT).EndCurrentEdit()
    End Sub  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox which populated from using a datatable. I have a Add
I have ListBox called lstProductGroups. On a simple Windows Form, a method called GetGroups
I have a listbox containing Users. The datasource is an generic list of the
I have a ListBox with databinding. I need to fire an event when a
I have listbox which binds data to DataTable and now I need to access
I have Window that has a ListBox ListBox(MyListBox) has a DataTable for its DataContext
i have a listbox that is populated this way with two Databindings (Frage and
I have a multi-select listbox which I am binding to a DataTable. DataTable contains
I have ListBox and want to put values in this listbox from a DataTable
I have ListBox data bind to list of users (collection): usersListBox.DataSource = null; usersListBox.DataSource

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.