Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please can some one help me with a datagrid layout problem due to .New

Status
Not open for further replies.

00755

Programmer
Mar 31, 2005
6
0
0
GB
HI,

Can some one please help me with a datagrid layout problem am having. Please see image below to see the problem:


<img src="
As you can see the data in each column do not line up, there broken up by new line spaces:



my code is shown below: I think the problem is due to me using the "dr = dt.NewRow(); line 22;" in the loop, Is there another way of declaring dr so that it does inseart newrow each time. or any idea's on how to fix this problem.






1 myDataAdapter.SelectCommand.CommandText = "SELECT recordid2,criteria,department,subheading," + pupids + " FROM [" + schooltid + "recordcriteriatbl] where department=@Field1l and recordtitle=@Field2l";
2
3 myDataAdapter.SelectCommand.Parameters.Add("@Field1l", dep);
4 myDataAdapter.SelectCommand.Parameters.Add("@Field2l", record);
5 SqlCommandBuilder custCB = new SqlCommandBuilder(myDataAdapter);
6
7
8
9 DataSet custDS = new DataSet();
10 myDataAdapter.Fill(custDS, "recordtitle");
11
12 foreach (DataTable table in custDS.Tables)
13 {
14 foreach (DataRow row in table.Rows)
15 {
16
17 string criteriaid = System.Convert.ToString(row["recordid2"]);
18 string criteria = System.Convert.ToString(row["criteria"]);
19 string sub = System.Convert.ToString(row["subheading"]).Trim();
20
21
22 dr = dt.NewRow();
23 if (sub == intArray[0])
24 {
25 dr[0] = criteria;
26 }
27 if (sub == intArray[1])
28 {
29 dr[1] = criteria;
30 }
31 if (sub == intArray[2])
32 {
33 dr[2] = criteria;
34 }
35 if (sub == intArray[3])
36 {
37 dr[3] = criteria;
38 }
39
40 dt.Rows.Add(dr);
41 }
42
43
44
45 }






Thank you for your time and help
 
I'm thinking you need to go through the Data Rows in your Data table for as many columns as you have.

on the first pass add all data to your new datatable for column one, second pass for column 2, etc.

So inside your for each Datarow line, for a for next loop to go through the columns and add data to your new data row columsn that way.

forgive me if this doesnt make sense, it is 5am :p :)
 
Hi Tperri,

Thank you for your reply, I understand you a little, could you show me little bit in code as still new to c# and unsure how to do what you said.

Thank you again for your time and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top