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

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2006
Posts: 8
Reputation: jcrcarmo is an unknown quantity at this point 
Solved Threads: 0
jcrcarmo jcrcarmo is offline Offline
Newbie Poster

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

 
0
  #1
Feb 23rd, 2006
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

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

 
0
  #2
Feb 23rd, 2006
  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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 8
Reputation: jcrcarmo is an unknown quantity at this point 
Solved Threads: 0
jcrcarmo jcrcarmo is offline Offline
Newbie Poster

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

 
-1
  #3
Feb 23rd, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC