c1Inputpanel set datasource at run-time

Posted by: levanduyet on 19 November 2023, 12:55 am EST

  • Posted 19 November 2023, 12:55 am EST - Updated 19 November 2023, 1:00 am EST

    Hi,

    I am new in c1InputPanel.

    I stuck with the setting Datasource at run-time for c1InputPanel.

    My existing project that I connect to database and return DataTable in the code.

    So how I set Datasource for c1InputPanel at run-time and how it update to other controls.

    My code is as following:

    public partial class frmTest : Form
        {
            public frmTest()
            {
                InitializeComponent();
                Boms oBom= new Boms();
                DataTable dtResult = oBom.GetDistinctBom();
                if(dtResult != null)
                {
                    this.bindingSource.DataSource = dtResult;
                }
            }
        }


    And when I run, It looks like nothing happen.

    Thanks,

    Duyet Le

  • Posted 20 November 2023, 4:11 am EST

    Hi Duyet,

    To bind the InputPanel components with the fields of your DataSource, you will need to set their DataSource and DataField properties. Please see the attached sample project for reference.

    InputPanelBinding.zip

    Best Regards,

    Kartik

  • Posted 20 November 2023, 11:55 am EST - Updated 20 November 2023, 12:00 pm EST

    Hi Kartik,

    I have followed with the following code:

    public partial class frmTest : Form
        {
            public frmTest()
            {
                InitializeComponent();
                Boms oBom= new Boms();
                DataTable dtResult = oBom.GetDistinctBom();
                if(dtResult != null)
                {
                    BindingSource bs = new BindingSource(dtResult, string.Empty);
                    //Set the Binding for the InputPanel components
                    SetInputTextBinding(inputTextBox1, bs, "prefixMattCode");
                    SetInputTextBinding(inputTextBox2, bs, "mattGroupName01");
                }
            }
            private void SetInputTextBinding(InputComponent inputTextBox, object dataSource, string dataField)
            {
                //Set DataSource and DataField properties for the InputPanel components
                inputTextBox.DataSource = dataSource;
                inputTextBox.DataField = dataField;
            }
        }


    But it does not show any thing as the attached photo.

    I want the InputPanel to enable for user to ADD/UPDATE/DELETE record of the Table.

    Thanks,

    Duyet Le

  • Posted 21 November 2023, 6:05 am EST

    Hi Duyet,

    We tested the InputTextBox and InputDataNavigator with the code we shared in our previous response, and they both are working fine. Please see the attached sample project showing the same.

    If you have a different implementation that is causing an issue, please share a sample project or update the attached project to reproduce the issue you are facing, so we can investigate further and assist you in the best way possible.

    Attachment: InputPanelBinding_Updated.zip

    Kind Regards,

    Kartik

  • Posted 21 November 2023, 12:20 pm EST - Updated 21 November 2023, 12:25 pm EST

    Hi Kartik,

    Thank you for help.

    I have followed your code, so my code as following:

    [code]using System.Windows.Forms;

    using DALC4NET;

    using warehousecontrol.BusinessLayer;

    using C1.Win.C1InputPanel;

    namespace warehousecontrol

    {

    #region Tham khảo
    //http://www.codeproject.com/Articles/15013/Windows-Forms-User-Settings-in-C
    //Save setting: lưu các biến vào setting của chương trình
    #endregion
    
    #region Khai báo các biến dùng chung/Common varianct
    //private frmMain frmParent;
    //private DBHelper _dbHelper = new DBHelper();
    #endregion
    
    #region Các hàm hỗ trợ/Support functions
    
    #endregion
    
    #region Methods and functions; Add, Edit, Delete, Exist
    
    #endregion
    public partial class frmTest : Form
    {
        static BindingSource bs;
        public frmTest()
        {
            InitializeComponent();
            Boms oBom= new Boms();
            DataTable dtResult = oBom.GetMattGroupInfo();
            if(dtResult != null)
            {
                bs = new BindingSource(dtResult, string.Empty);
                //Set the Binding for the InputPanel components
                SetInputComponentBinding(inputTextBox1, bs, "prefixMattCode");
                SetInputComponentBinding(inputTextBox2, bs, "mattGroupName01");
                SetInputComponentBinding(inputDataNavigator1, bs, string.Empty);
            }
        }
        private void SetInputComponentBinding(InputComponent inputTextBox, object dataSource, string dataField)
        {
            //Set DataSource and DataField properties for the InputPanel components
            inputTextBox.DataSource = dataSource;
            inputTextBox.DataField = dataField;
        }
    }
    

    }[/code]

    So now I could move next, backward.

    I have tried to add/edit/save change by the button on the c1inputpanel.

    When I close it, open again, it does not change any things.

    So, how can I make a change to table.



    Sorry, as I am new on this.

    Thank you.

    Duyet Le

  • Posted 22 November 2023, 3:03 am EST

    Hi Duyet,

    We tested our code and it working completely fine. The add/edit/save buttons commit the changes to the DataTable attached through the BindingSource. For testing, we have added a DataGridView to the form which shows all the changes being reflected.

    After the DataTable is updated, please make sure to update the changes back to your Database. You can use the DataTable events for this. Then only the changes will be observed after you close and reopen the application (We are assuming that at this time, the data is loaded from the Database).

    Please refer to the updated sample project for reference. If you still face any issues, please share a sample project, or else we won’t be able to understand your issue and assist you further.

    InputPanelBinding_DataUpdatedCorrect.zip

    Best Regards,

    Kartik

  • Posted 28 November 2023, 3:42 am EST

    Hi Kartik,

    I have checked your project, it’s also not update.

    Could you have a small project with Ms.Access Database for testing.

    Thanks,

    Duyet Le

  • Posted 29 November 2023, 4:19 am EST

    Hi Duyet,

    We have updated the sample project with the MS Access database. You will notice that if you change the data and apply the changes, closing and opening the application again will persist all changes. We have also included a video showing the behavior.

    InputPanelBinding_DbUpdate.zip

    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