I am trying to add a row for data table whenever we click on a button and for n clicks n rows of textboxes properties along with its text values should be added to n datarows of a datatable.Entire code is fine but the run time text values were not getting added.Please help me and thanks in advance

(Kindly Have a look at rar file for the output)
- namespace DataTableExample
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- internal TextBox tb2;
- internal int X = 1;
- internal int A = 1;
- DataTable dt = new DataTable();
- DataRow dr;
- private void Button1_Click(object sender, EventArgs e)
- {
- if (X <13)
- {
- Show();
- X++;
- }
- else
- {
- MessageBox.Show("Only 12 values per page");
- }
- }
- private new void Show()
- {
- tb2 = new TextBox();
- tb2.Multiline = true;
- //tb2.Text = UserControl.;
- tb2.Height = 22;
- tb2.Width = 60;
- tb2.Left = 43;
- tb2.Top = 140 + A* 36;
- this.Controls.Add(tb2);
- A+=1;
- dr = dt.NewRow();
- dr["text"] = tb2.Text;
- dr["Height"] = tb2.Height;
- dr["Width"] = tb2.Width;
- dr["Left"] = tb2.Left;
- dr["Top"] = tb2.Top;
- dt.Rows.Add(dr);
- }
- private void Button2_Click(object sender, EventArgs e)
- {
- dataGridView1.DataSource = dt;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- dt.Columns.Add("text",typeof(String));
- dt.Columns.Add("Height",typeof(int));
- dt.Columns.Add("Width", typeof(int));
- dt.Columns.Add("Left", typeof(int));
- dt.Columns.Add("Top", typeof(int));
- }
- }
- }
Amit MohantyPosted Sep 18, 2019, 5:32 AM
Jayanth ReddyPosted Sep 18, 2019, 6:16 AM
Jayanth ReddyPosted Sep 18, 2019, 5:31 AM
Rajanikant HawaldarPosted Sep 18, 2019, 3:55 AM