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 9030097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:24:19+00:00 2026-06-16T07:24:19+00:00

I have a win form which has a ListBox . I want to create

  • 0

I have a win form which has a ListBox. I want to create dynamically a DataTable (till now I only declared some columns – you can see in the code – that I later want to use to link the DataTable to an existing empty DataBase) but don’t know how to link it to the Listbox in order to “take” the 4 elements from it: event_time , event_filename , event_name , event_fullpath. Pls Help,

Part of my code till now is:

    private delegate void AppendListHandler(string event_filename, String event_name, String event_fullpath);

    private void AppendText(string event_filename, String event_name, String event_fullpath)
    {
        if (lstResultLog.InvokeRequired)
            lstResultLog.Invoke(new AppendListHandler(AppendText), new object[] { event_filename, event_name, event_fullpath });
        else
        {
            DateTime event_time = DateTime.Now;
            //String event_duration = event_time.ToString("HH:mm");
            lstResultLog.Items.Add(event_time + event_filename + event_name + event_fullpath);
        }

        DataTable table = new DataTable("tbl_Event");
        table.Columns.Add("event_duration");
        table.Columns.Add("event_name");
        table.Columns.Add("event_filename");
        table.Columns.Add("event_fullpath");
        table = (DataTable)lstResultLog.DataSource;
    }

lstResultLog is the name of the ListBox, all the fields from the ListBox have the exact name as in the declared DataTable, and as the DataBase.

  • 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-16T07:24:20+00:00Added an answer on June 16, 2026 at 7:24 am

    You can have in your form a field of type DataTable that will hold the data you want. Then, whenever you add an item to your listbox, add a row to the data table with same data:

    public class YourForm
    {
        private DataTable _table;
        public YourForm()
        {
            InitializeComponents();
            _table = BuildDataTable();
        }
    
        private DataTable BuildDataTable()
        {
            DataTable table = new DataTable("tbl_Event");
            table.Columns.Add("event_duration");
            table.Columns.Add("event_name");
            table.Columns.Add("event_filename");
            table.Columns.Add("event_fullpath");
            return table;
        }
    
        private void AppendText(string event_filename, String event_name, String event_fullpath)
        {
            if (lstResultLog.InvokeRequired)
                lstResultLog.Invoke(new AppendListHandler(AppendText), new object[] { event_filename, event_name, event_fullpath });
            else
            {
                DateTime event_time = DateTime.Now;
                lstResultLog.Items.Add(event_time + event_filename + event_name + event_fullpath);
                //Create new row
                var row = _table.NewRow();
                // Fill row values
                row["event_name"] = event_name;
                // Add row to table
                _table.Rows.Add(row);
            }
        }
    }
    

    And when you need to send the data to database, just send _table field as a parameter to the method that saves data.

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

Sidebar

Related Questions

I have a winform form which has typical OK and Cancel buttons. The OK
I have a Winform DataGridView , which has a number of predefined columns. Now
I have a User Control that has some WinForm Controls inside. I want to
I Have a Windows Form Project , which has a main form,and in this
Hi I have a web app which has a listbox of all the available
I have a windows installer project which installs some software (winform, service, mce addin).
I am working on win-form app that has . net 2.0 as framework. I
My goal is to create a C# winform application which has rounded panel, rounded
I have HTML template which has empty forms. How can i fill these forms
We have a desktop application, which has been provided a web UI by hosting

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.