Windows Form Table

SeanPress 206 Reputation points
2023-12-28T10:37:12.59+00:00

Hi,

I would like to add a user input table to a windows form, I would like the user to be able to enter the number of rows required but restrict the maximum number of rows to 6.

The table would have 5 columns, (1 description entry & 4 numerical value entries) & the user can either select the number of rows required from a drop down list or enter the number in a textbox or something, but only be able to enter a maximum of 6 rows.

I would then like use the to numerical values entered to calculate various equations & create a chart.

I am not very experienced with coding but would appreciate it if anyone could tell me if this is possible & hopefully provide some guidance on how to do this.

Best Regards,

Sean

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2023-12-28T11:06:28.59+00:00

    hopefully provide some guidance on how to do this.

    Mainly you can use a DataGridView Control (Windows Forms) to enter data row-wise.

    The article have several links with guidance & details, go through them.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. machbrown2 0 Reputation points
    2023-12-28T11:14:39.39+00:00

    Hello,

    If you want to create a table-like structure in a Windows Forms application using C#, you can use the DataGridView control. The DataGridView control is a versatile control that allows you to display and edit data in tabular format. Here's a simple example to get you started:

    1. Open Visual Studio and create a new Windows Forms Application project.
    2. Drag and drop a DataGridView control from the Toolbox onto your form.
    3. Set the properties of the DataGridView control, such as Name (e.g., dataGridView1) and adjust its size.
    4. Open the code-behind file (Form1.cs) and add the following code:
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace WindowsFormsTableExample
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                // Call a method to populate the DataGridView with data
                PopulateDataGridView();
            }
    
            private void PopulateDataGridView()
            {
                // Create a list of data (you can replace this with your data source)
                List<Person> people = new List<Person>
                {
                    new Person { Name = "John", Age = 25, City = "New York" },
                    new Person { Name = "Jane", Age = 30, City = "Los Angeles" },
                    new Person { Name = "Bob", Age = 22, City = "Chicago" }
                };
    
                // Bind the list to the DataGridView
                dataGridView1.DataSource = people;
            }
    
            // Define a simple data model (replace this with your actual data model)
            public class Person
            {
                public string Name { get; set; }
                public int Age { get; set; }
                public string City { get; set; }
            }
        }
    }
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.