943,741 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 18295
  • C# RSS
Feb 23rd, 2006
0

C# .Net 2005 - Question about .Row.Add(new object[]{...,...}) Please help!

Expand Post »
Hello everyone,

Greetings from Brazil! As shown in the code below, is it possible for me to add the new objects for tipoDT and sementesDT without having to do it one-by-one? Like, for example, getting the values automatically from the tables?.... How would I do that? The sementesDT table is quite large and would take me forever to add the new objects one-by-one! Here's the code:

C# Syntax (Toggle Plain Text)
  1. public frmBA()
  2. {
  3. tipoDT = new DataTable("tabTipoSemente");
  4. tipoDT.Columns.Add("CodTipo", typeof(int));
  5. tipoDT.Columns.Add("Tipo", typeof(string));
  6.  
  7. tipoDT.Rows.Add(new object[] { 0, "Nocivas Probidas" });
  8. tipoDT.Rows.Add(new object[] { 1, "Nocivas Toleradas" });
  9. tipoDT.Rows.Add(new object[] { 2, "Sementes Silvestres" });
  10.  
  11. sementesDT = new DataTable("tabSementes");
  12. sementesDT.Columns.Add("CodSemente", typeof(int));
  13. sementesDT.Columns.Add("CodTipo", typeof(int));
  14. sementesDT.Columns.Add("Semente", typeof(string));
  15.  
  16. sementesDT.Rows.Add(new object[] { 0, 0, "SubCat0-Cat0" });
  17. sementesDT.Rows.Add(new object[] { 1, 0, "SubCat1-Cat0" });
  18. sementesDT.Rows.Add(new object[] { 2, 0, "SubCat2-Cat0" });
  19. sementesDT.Rows.Add(new object[] { 3, 1, "SubCat3-Cat1" });
  20. sementesDT.Rows.Add(new object[] { 4, 1, "SubCat4-Cat1" });
  21. sementesDT.Rows.Add(new object[] { 5, 1, "SubCat5-Cat1" });
  22. sementesDT.Rows.Add(new object[] { 6, 2, "SubCat6-Cat2" });
  23. sementesDT.Rows.Add(new object[] { 7, 2, "SubCat7-Cat2" });
  24. sementesDT.Rows.Add(new object[] { 8, 2, "SubCat8-Cat2" });
  25.  
  26. InitializeComponent();
  27.  
  28. tipoBS = new BindingSource();
  29. tipoBS.DataSource = tipoDT;
  30. TipoComboBoxColumn.DataSource = tipoBS;
  31. TipoComboBoxColumn.DisplayMember = "Tipo";
  32. TipoComboBoxColumn.ValueMember = "CodTipo";
  33.  
  34. unfilteredSementesBS = new BindingSource();
  35. DataView undv = new DataView(sementesDT);
  36. unfilteredSementesBS.DataSource = undv;
  37. EspecieComboBoxColumn.DataSource = unfilteredSementesBS;
  38. EspecieComboBoxColumn.DisplayMember = "Semente";
  39. EspecieComboBoxColumn.ValueMember = "CodTipo";
  40.  
  41. filteredSementesBS = new BindingSource();
  42. DataView dv = new DataView(sementesDT);
  43. filteredSementesBS.DataSource = dv;
  44. }

Thank you very much for your attention, time and help and I'm looking forward to your reply.

Best regards,

JC Carmo
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jcrcarmo is offline Offline
8 posts
since Feb 2006
Feb 23rd, 2006
0

Re: C# .Net 2005 - Question about .Row.Add(new object[]{...,...}) Please help!

C# Syntax (Toggle Plain Text)
  1. sementesDT.Rows.Add(new object[] { 0, 0, "SubCat0-Cat0" });
  2. sementesDT.Rows.Add(new object[] { 1, 0, "SubCat1-Cat0" });
  3. sementesDT.Rows.Add(new object[] { 2, 0, "SubCat2-Cat0" });
  4. sementesDT.Rows.Add(new object[] { 3, 1, "SubCat3-Cat1" });
  5. sementesDT.Rows.Add(new object[] { 4, 1, "SubCat4-Cat1" });
  6. sementesDT.Rows.Add(new object[] { 5, 1, "SubCat5-Cat1" });
  7. sementesDT.Rows.Add(new object[] { 6, 2, "SubCat6-Cat2" });
  8. sementesDT.Rows.Add(new object[] { 7, 2, "SubCat7-Cat2" });
  9. sementesDT.Rows.Add(new object[] { 8, 2, "SubCat8-Cat2" });
i am assuming you are talking about this line
you should be able to do this in a loop
where are you getting this information from? database, spreadsheet, text document?
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Feb 23rd, 2006
-1

Re: C# .Net 2005 - Question about .Row.Add(new object[]{...,...}) Please help!

Hi campkev! Thanks for your reply. Yes, I am talking about this line, but I have already found a way to do what I wanted and will post the solution here, if that's ok. Thank you very much for your kind attention, time and help.

JC
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jcrcarmo is offline Offline
8 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Develop a software to remove duplication
Next Thread in C# Forum Timeline: extending windows "file system" attributes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC