How to generate datagrid without knowing # of rows (not retrieving form a database)

H

Hai Nguyen

Hi all

I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this

Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)


My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)

2/ Because the header is stored in a ArrayList, how do i bind those to the
header

3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?

4/ If users want to insert more than the rows printing, how can they add
more rows?

I appreciate any idea to get this problem solve.

PS: If we can n't solve in datagrid, any solutions will be my big help

Thanks everyone
 
A

Alvin Bruney

What you would need to do is build a datagrid manually one row at a time as
needed. When you construct a row, you will set the caption name and the
value items as you go along. This code creates 4 column datagrid. then adds
rows to it as needed

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

{

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[4]= 0.00;

if(Double.TryParse(ds2.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[4]= input.ToString();


myRow[3]= 0.00;

if(Double.TryParse(ds.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[3]= input.ToString();


if(Double.TryParse((Double.Parse(myRow[3].ToString()) -
Double.Parse(myRow[4].ToString())).ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[2]= input.ToString();

if(ds2.Tables[0].Rows[0][col].ToString().Trim() != String.Empty)

myRow[1]= Math.Round(((Double.Parse(myRow[2].ToString()) /
Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100),2);


myRow[0]= ds.Tables[0].Columns[col].ColumnName;

dsTemp.Tables[0].Rows.Add(myRow);

}

Feel free to modify the code as you see fit.
 
H

Hai Nguyen

I'm sorry for asking you dump question. There are some part of your code I don't understand. Would you please feel free to explain it to me


dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );
dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType( "System.Double" ) );
dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType("System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("ddddMM/dd/yyyy"), System.Type.GetType"System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("ddddMM/dd/yyyy"), System.Type.GetType ("System.Double" ) );

What does it mean?

Thanks


Alvin Bruney said:
What you would need to do is build a datagrid manually one row at a time as
needed. When you construct a row, you will set the caption name and the
value items as you go along. This code creates 4 column datagrid. then adds
rows to it as needed

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

{

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[4]= 0.00;

if(Double.TryParse(ds2.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[4]= input.ToString();


myRow[3]= 0.00;

if(Double.TryParse(ds.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[3]= input.ToString();


if(Double.TryParse((Double.Parse(myRow[3].ToString()) -
Double.Parse(myRow[4].ToString())).ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[2]= input.ToString();

if(ds2.Tables[0].Rows[0][col].ToString().Trim() != String.Empty)

myRow[1]= Math.Round(((Double.Parse(myRow[2].ToString()) /
Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100),2);


myRow[0]= ds.Tables[0].Columns[col].ColumnName;

dsTemp.Tables[0].Rows.Add(myRow);

}

Feel free to modify the code as you see fit.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Hai Nguyen said:
Hi all

I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this

Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)


My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)

2/ Because the header is stored in a ArrayList, how do i bind those to the
header

3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?

4/ If users want to insert more than the rows printing, how can they add
more rows?

I appreciate any idea to get this problem solve.

PS: If we can n't solve in datagrid, any solutions will be my big help

Thanks everyone
 
A

Alvin Bruney

this builds a grid like so
% variance raw variance Wednesday 01/14/2004 Wednesday 01/07/2004


then you build the rows to fill out the grid. Make sense?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
I'm sorry for asking you dump question. There are some part of your code I don't understand. Would you please feel free to explain it to me


dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );
dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType( "System.Double" ) );
dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType("System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("ddddMM/dd/yyyy"), System.Type.GetType"System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("ddddMM/dd/yyyy"), System.Type.GetType ("System.Double" ) );

What does it mean?

Thanks


Alvin Bruney said:
What you would need to do is build a datagrid manually one row at a time as
needed. When you construct a row, you will set the caption name and the
value items as you go along. This code creates 4 column datagrid. then adds
rows to it as needed

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

{

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[4]= 0.00;

if(Double.TryParse(ds2.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[4]= input.ToString();


myRow[3]= 0.00;

if(Double.TryParse(ds.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[3]= input.ToString();


if(Double.TryParse((Double.Parse(myRow[3].ToString()) -
Double.Parse(myRow[4].ToString())).ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[2]= input.ToString();

if(ds2.Tables[0].Rows[0][col].ToString().Trim() != String.Empty)

myRow[1]= Math.Round(((Double.Parse(myRow[2].ToString()) /
Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100),2);


myRow[0]= ds.Tables[0].Columns[col].ColumnName;

dsTemp.Tables[0].Rows.Add(myRow);

}

Feel free to modify the code as you see fit.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Hai Nguyen said:
Hi all

I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this

Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)


My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)

2/ Because the header is stored in a ArrayList, how do i bind those to the
header

3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?

4/ If users want to insert more than the rows printing, how can they add
more rows?

I appreciate any idea to get this problem solve.

PS: If we can n't solve in datagrid, any solutions will be my big help

Thanks everyone
 
H

Hai Nguyen

Thank you Alvin, you are awesome


"Alvin Bruney" <vapor at steaming post office> wrote in message this builds a grid like so
% variance raw variance Wednesday 01/14/2004 Wednesday 01/07/2004


then you build the rows to fill out the grid. Make sense?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
I'm sorry for asking you dump question. There are some part of your code I don't understand. Would you please feel free to explain it to me


dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );
dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType( "System.Double" ) );
dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType("System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("ddddMM/dd/yyyy"), System.Type.GetType"System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("ddddMM/dd/yyyy"), System.Type.GetType ("System.Double" ) );

What does it mean?

Thanks


Alvin Bruney said:
What you would need to do is build a datagrid manually one row at a time as
needed. When you construct a row, you will set the caption name and the
value items as you go along. This code creates 4 column datagrid. then adds
rows to it as needed

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

{

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[4]= 0.00;

if(Double.TryParse(ds2.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[4]= input.ToString();


myRow[3]= 0.00;

if(Double.TryParse(ds.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[3]= input.ToString();


if(Double.TryParse((Double.Parse(myRow[3].ToString()) -
Double.Parse(myRow[4].ToString())).ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[2]= input.ToString();

if(ds2.Tables[0].Rows[0][col].ToString().Trim() != String.Empty)

myRow[1]= Math.Round(((Double.Parse(myRow[2].ToString()) /
Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100),2);


myRow[0]= ds.Tables[0].Columns[col].ColumnName;

dsTemp.Tables[0].Rows.Add(myRow);

}

Feel free to modify the code as you see fit.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Hai Nguyen said:
Hi all

I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this

Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)


My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)

2/ Because the header is stored in a ArrayList, how do i bind those to the
header

3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?

4/ If users want to insert more than the rows printing, how can they add
more rows?

I appreciate any idea to get this problem solve.

PS: If we can n't solve in datagrid, any solutions will be my big help

Thanks everyone
 
A

Alvin Bruney

just be sure to help someone else. that's what this place is about

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Thank you Alvin, you are awesome


"Alvin Bruney" <vapor at steaming post office> wrote in message this builds a grid like so
% variance raw variance Wednesday 01/14/2004 Wednesday 01/07/2004


then you build the rows to fill out the grid. Make sense?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
I'm sorry for asking you dump question. There are some part of your code I don't understand. Would you please feel free to explain it to me


dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );
dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType( "System.Double" ) );
dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType("System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("ddddMM/dd/yyyy"), System.Type.GetType"System.Double" ) );
dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("ddddMM/dd/yyyy"), System.Type.GetType ("System.Double" ) );

What does it mean?

Thanks


Alvin Bruney said:
What you would need to do is build a datagrid manually one row at a time as
needed. When you construct a row, you will set the caption name and the
value items as you go along. This code creates 4 column datagrid. then adds
rows to it as needed

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( "raw variance", System.Type.GetType(
"System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-1).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

dsTemp.Tables[0].Columns.Add( DateTime.Now.AddDays(-8).ToString("dddd
MM/dd/yyyy"), System.Type.GetType( "System.Double" ) );

for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

{

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[4]= 0.00;

if(Double.TryParse(ds2.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[4]= input.ToString();


myRow[3]= 0.00;

if(Double.TryParse(ds.Tables[0].Rows[0][col].ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[3]= input.ToString();


if(Double.TryParse((Double.Parse(myRow[3].ToString()) -
Double.Parse(myRow[4].ToString())).ToString(),
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out input))

myRow[2]= input.ToString();

if(ds2.Tables[0].Rows[0][col].ToString().Trim() != String.Empty)

myRow[1]= Math.Round(((Double.Parse(myRow[2].ToString()) /
Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100),2);


myRow[0]= ds.Tables[0].Columns[col].ColumnName;

dsTemp.Tables[0].Rows.Add(myRow);

}

Feel free to modify the code as you see fit.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Hai Nguyen said:
Hi all

I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this

Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)


My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)

2/ Because the header is stored in a ArrayList, how do i bind those to the
header

3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?

4/ If users want to insert more than the rows printing, how can they add
more rows?

I appreciate any idea to get this problem solve.

PS: If we can n't solve in datagrid, any solutions will be my big help

Thanks everyone
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top