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

  • SEARCH
  • Home
  • 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 8308199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:43:44+00:00 2026-06-08T18:43:44+00:00

I have a form for my update method, the form is in detail view.

  • 0

I have a form for my update method, the form is in detail view. Next to the textboxes I have a listbox which shows the names of all the names in the database table. Under the listbox I also have an extra textbox to quick search the name in case user would like to type it in.

When I go to update one of the names, such as changing John to Jonathan, the database updates with the new name as I have checked on sql server, but the name in the listbox does not change! There’s a dirty way to fix this by moving the position the listbox is selected on currently to movefirst(). However, under the listbox I have the textbox which is a quick search as I’ve mentioned, so I go to type Jonathan in the search text box, but nothing appears. However, if I type the former name John, then I get the details of this row in the table.

Is there a way I can fix this?

UPDATE 1:

Ive tried making the listbox datasource null then reassigning it again but it doesen’t work. Ive put my code for my update form below.


namespace WindowsFormsApplication1
{
public partial class updateContact : Form
{
public updateContact()
{
InitializeComponent();
}

    private void updateContact_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'tblcontactsupdate.tblContacts' table. You can move, or remove it, as needed.
        this.tblContactsTableAdapter.Fill(this.tblcontactsupdate.tblContacts);
    }
    private void btnUpdateContact_Click(object sender, EventArgs e)
    {
        int x;

        Program.da.UpdateCommand = new SqlCommand("Update tblContacts SET FIRSTNAME = @FIRSTNAME, LASTNME = @LASTNME WHERE ID = @ID", Program.cs);
        Program.da.UpdateCommand.Parameters.Add("@FIRSTNAME", SqlDbType.VarChar).Value = fIRSTNAMETextBox.Text;
        Program.da.UpdateCommand.Parameters.Add("@LASTNME", SqlDbType.VarChar).Value = lASTNMETextBox.Text;
        Program.da.UpdateCommand.Parameters.Add("@ID", SqlDbType.VarChar).Value = iDTextBox.Text;

        Program.cs.Open();
        x = Program.da.UpdateCommand.ExecuteNonQuery();
        Program.cs.Close();

        if (x >= 1)
        {
            MessageBox.Show("Record(s) has been updated");
            Program.ds.Clear();
            Program.da.Fill(Program.ds);
            txtfindUpdatecontact.Text = "";
            //lbupdateContact.DataSource = null;
            //lbupdateContact.DataSource = this.tblcontactsupdate.tblContacts;
        }       
    }
    private void txtfindUpdatecontact_TextChanged(object sender, EventArgs e)
    {
        if (!txtfindUpdatecontact.Text.Equals(""))
        {
            this.tblContactsBindingSource.Filter = "FIRSTNAME = '" + txtfindUpdatecontact.Text + "'";

        }
        else
        {
            this.tblContactsBindingSource.RemoveFilter();
        }
    }

    private void lbupdateContact_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    private void iDTextBox_TextChanged(object sender, EventArgs e)
    {

    }

    private void fIRSTNAMETextBox_TextChanged(object sender, EventArgs e)
    {

    }

    private void lASTNMETextBox_TextChanged(object sender, EventArgs e)
    {

    }
}

}

  • 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-08T18:43:46+00:00Added an answer on June 8, 2026 at 6:43 pm

    You will have to set the DataSource of your listbox one more time after updating the source.

    Something like below: It’s my data:

     public class Person
        {
            public int Age { get; set; }
            public string Name { get; set; }
        }
    
        public class MyDataSource
        {
            public static List<Person> Persons = new List<Person>
            {
                new Person{Age=30,Name="Ram"},
                new Person{Age=33,Name="Rahim"},
            };
        }
    

    then in the form’s constructor you can do:

     listBox1.DataSource = MyDataSource.Persons;
     listBox1.DisplayMember = "Age";
    

    then for updation, something like below:

    private void button1_Click(object sender, EventArgs e)
            {
                MyDataSource.Persons[0].Age = 45;
                listBox1.DataSource = null;
                listBox1.DataSource = MyDataSource.Persons;
                listBox1.DisplayMember = "Age";
            }
    

    This is just an example change code according to your need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form view which people use to update a record in the
I have a calendar_date_select in a view that shows a table listing all the
I'm trying to update a table from a form. I have 3 pages. The
I've creating one ASP web application, in that application one form have to update
I have a form that enables a user to update multiple alert rules records
UPDATE 6/21/12 I have a form in rails that is working similar to an
I have a MDI container form, and some child forms that update their title
I have an html/php form that updates entries on the database server. I need
I have a page which displays a form that a logged-in user can use
I have a Customer class which has all the account info.(it does NOT extend

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.