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

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

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

    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:

    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

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you are using a database and you want to fill the DataTable with info from that, then you can use the DataAdapter class and call Fill on a DataSet. The structure of the DataTable will be done as well as the data.

    If you want to fill the dataset yourself, add a DataSet to your project, then add what DataTables you need using tyhe editor. You can set the column values at Design time (data type, AutoIncrement etc..). Then at Runtime, just fill the DataSet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. migrate from .Net 2.0 to .Net 3.0
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 07-25-2007, 04:07 AM
  2. Question with VC++ .NET
    By Driveway in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-27-2002, 09:06 AM
  3. Curios Visual C++ .NET question.
    By Progmammer in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2002, 01:29 PM
  4. .NET question
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 04-26-2002, 08:58 PM
  5. another question about .net
    By Sekti in forum C++ Programming
    Replies: 9
    Last Post: 04-01-2002, 03:36 PM