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:

public frmBA() 
       { 
           tipoDT = new DataTable("tabTipoSemente"); 
           tipoDT.Columns.Add("CodTipo", typeof(int)); 
           tipoDT.Columns.Add("Tipo", typeof(string)); 

           tipoDT.Rows.Add(new object[] { 0, "Nocivas Probidas" }); 
           tipoDT.Rows.Add(new object[] { 1, "Nocivas Toleradas" }); 
           tipoDT.Rows.Add(new object[] { 2, "Sementes Silvestres" }); 

           sementesDT = new DataTable("tabSementes"); 
           sementesDT.Columns.Add("CodSemente", typeof(int)); 
           sementesDT.Columns.Add("CodTipo", typeof(int)); 
           sementesDT.Columns.Add("Semente", typeof(string)); 

           sementesDT.Rows.Add(new object[] { 0, 0, "SubCat0-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 1, 0, "SubCat1-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 2, 0, "SubCat2-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 3, 1, "SubCat3-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 4, 1, "SubCat4-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 5, 1, "SubCat5-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 6, 2, "SubCat6-Cat2" }); 
           sementesDT.Rows.Add(new object[] { 7, 2, "SubCat7-Cat2" }); 
           sementesDT.Rows.Add(new object[] { 8, 2, "SubCat8-Cat2" }); 

           InitializeComponent(); 

           tipoBS = new BindingSource(); 
           tipoBS.DataSource = tipoDT; 
           TipoComboBoxColumn.DataSource = tipoBS; 
           TipoComboBoxColumn.DisplayMember = "Tipo"; 
           TipoComboBoxColumn.ValueMember = "CodTipo"; 

           unfilteredSementesBS = new BindingSource(); 
           DataView undv = new DataView(sementesDT); 
           unfilteredSementesBS.DataSource = undv; 
           EspecieComboBoxColumn.DataSource = unfilteredSementesBS; 
           EspecieComboBoxColumn.DisplayMember = "Semente"; 
           EspecieComboBoxColumn.ValueMember = "CodTipo"; 

           filteredSementesBS = new BindingSource(); 
           DataView dv = new DataView(sementesDT); 
           filteredSementesBS.DataSource = dv; 
       }

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

Best regards,

JC Carmo :)

Recommended Answers

All 2 Replies

sementesDT.Rows.Add(new object[] { 0, 0, "SubCat0-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 1, 0, "SubCat1-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 2, 0, "SubCat2-Cat0" }); 
           sementesDT.Rows.Add(new object[] { 3, 1, "SubCat3-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 4, 1, "SubCat4-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 5, 1, "SubCat5-Cat1" }); 
           sementesDT.Rows.Add(new object[] { 6, 2, "SubCat6-Cat2" }); 
           sementesDT.Rows.Add(new object[] { 7, 2, "SubCat7-Cat2" }); 
           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?

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.