TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jayanth Reddy
NA
250
9.7k
inserting dynamic textbox’s multiple text values to dataTabl
Sep 18 2019 2:07 AM
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
));
}
}
}
Attachment:
Task2.rar
Reply
Answers (
4
)
Enabling And Disabling Screen Capture In Windows application
How to get data from a booloean function in vb.net