Refreshing List After a Save

Posted by: GetInfo on 19 January 2024, 8:49 pm EST

  • Posted 19 January 2024, 8:49 pm EST

    This code fills the list perfectly.

    private void GetAllBits()

    {

    DataTable tbAllBits;

    String strFind;

    strFind = $"Select  tbRouterBits.counter, tbRouterBits.txtCode, tbRouterBits.intsize, tbRouterBits.txtDescription, tbRouterBits.txtNotes,  " +
        $"tbRouterBits.txtImageFile, tbRouterBits.txtImageDescription, tbGroups.txtDescription, tbGroups.ID from tbRouterBits join tbGroups ON tbGroups.ID =tbRouterBits.intGroup;";
    
    try
    {
        Fcon.Open(); 
    
        SqlCommand cmd = new SqlCommand(strFind, Fcon);
        tbAllBits = new DataTable();
        tbAllBits.Load(cmd.ExecuteReader());
    
        Fcon.Close();
    
        int numrowCount = tbAllBits.Rows.Count;
        if (numrowCount > 0)
        {
            lstBits.DataSource = tbAllBits;
            lstBits.DataMember = "txtDescription";
    
    
            numCount.Value = tbAllBits.Rows.Count;
            int fred = tbAllBits.Rows.Count;
         //   MessageBox.Show(Convert.ToString(fred));
    
            lstBits.Splits[0].DisplayColumns[0].Visible = false;
            lstBits.Splits[0].DisplayColumns[4].Visible = false;
            lstBits.Splits[0].DisplayColumns[8].Visible = false;
            lstBits.Splits[0].DisplayColumns[1].Width = 70;
            lstBits.Splits[0].DisplayColumns[2].Width = 80;
    
            lstBits.ColumnHeaders = false;
    
            lstBits.Splits[0].HeadingStyle.BackColor = Color.Black;
            lstBits.CaptionStyle.BackColor = Color.Black;
            lstBits.CaptionStyle.ForeColor = Color.Yellow;
            lstBits.Splits[0].HeadingStyle.ForeColor = Color.Yellow;
            lstBits.AlternatingRows = true;
            lstBits.Splits[0].EvenRowStyle.BackColor = Color.Beige;
            
            bolNeedToSave = false;
           // tbAllBits.Dispose();
        }
    }
    catch (Exception ex)
    
    {
        MessageBox.Show("Error 4100: Error info: " + ex.Message);
    }
    finally
    {
    }
    

    }

    When a new record is added and the code is run again to reflect the save and show the new record the list blanks. The datatable has the correct number of records but the control is blank.

  • Posted 21 January 2024, 6:03 pm EST

    Hi,

    We tried to reproduce the behavior as per your description, but the C1List is working fine on our end. We tested by loading the data into the C1List, adding a new record into the DataSource, and then loading the data into the C1List again. Please see the attached sample project for reference (ListDataSource.zip).

    If you are facing an issue with a different implementation, please update the sample project to reproduce the issue so we can investigate further and assist you better.

    Note: We tested the behavior with the latest 2023v3(631) release. If you are using an older version, please test with the latest version once to see if the issue persists.

    Thanks, and Best Regards,

    Kartik

  • Posted 22 January 2024, 10:45 am EST

    Your example uses a dataset with Access while mine uses a datatable with SQL. Does this make any difference to the operation of the list?

  • Posted 22 January 2024, 4:59 pm EST

    Hi,

    The usage of different databases does not affect the operation of the C1List. The C1List works based on the DataSource assigned to it (DataTable in this case). For confirmation, we also tested the behavior by following the same steps with the SQL Server and observed the same results. Below is the code that we updated in the previous sample project to fill the DataTable:

    var conn = @"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;";
    var comm = "Select * from [NewTable]";
    var da = new SqlDataAdapter(comm, conn);
    var dt = new DataTable("NewTable");
    da.Fill(dt);
    
    c1List1.DataSource = dt;

    Could you please once check with the latest 2023v3(636) version to see if you still face the issue? If the issue persists, we request you please provide a stripped-down version of your project that reproduces the issue. It would be really helpful for us to investigate the behavior further and assist you better.

    (https://www.nuget.org/packages/C1.Win.C1List/4.8.20233.636)

    Thanks, and Best Regards,

    Kartik

  • Posted 22 January 2024, 5:52 pm EST - Updated 22 January 2024, 5:57 pm EST



    Project as requested.

  • Posted 23 January 2024, 3:01 pm EST

    Hi,

    Did you intend to provide a sample project that reproduces the issue, as you stated “Project as requested”? We don’t see any attached projects, just a screenshot of the ComponentOne version. Please share a stripped-down version of your project or update the project that we attached in our initial response to reproduce the issue. It will help us in determining the cause of the behavior on your end.

    Thanks, and Best Regards,

    Kartik

  • Posted 23 January 2024, 6:09 pm EST

  • Posted 23 January 2024, 10:08 pm EST

    Hi,

    Thank you for providing the sample project and database file. The DataMember property is causing this behavior on your end. This property defines the name of the member from the DataSource that is to be used to populate the control.

    This property is generally used if you assign a DataSet as the DataSource and you want the control to be populated from a specific DataTable in the DataSet. Since you are directly assigning a DataTable as the DataSource, there is no need to define the DataMember property. Please see the updated sample project for reference - RouterBits_Updated.zip

    The below code is from the initial query that you posted. This should solve the error in your main project

    lstBits.DataSource = tbAllBits;
    //This line should be commented out
    //lstBits.DataMember = "txtDescription";

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels