Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# .Net 2005 - Question about .Row.Add(new object[]{...,...}) Please help!

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

Scheduled Pinned Locked Moved C#
csharpquestionhelptutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JC Carmo
    wrote on last edited by
    #1

    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 muc

    C 1 Reply Last reply
    0
    • J JC Carmo

      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 muc

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      JC Carmo wrote:

      Like, for example, getting the values automatically from the tables?....

      What tables ? If you mean in a database, then yes, that's what a dataset is really for. Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        JC Carmo wrote:

        Like, for example, getting the values automatically from the tables?....

        What tables ? If you mean in a database, then yes, that's what a dataset is really for. Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        JC Carmo
        wrote on last edited by
        #3

        I mean the tabSementes table that is referenced in the code. How do I connect it to a DataSet ? Thanks for your reply. JC.

        C 1 Reply Last reply
        0
        • J JC Carmo

          I mean the tabSementes table that is referenced in the code. How do I connect it to a DataSet ? Thanks for your reply. JC.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          A DataSet is a collection of DataTables, I'd assume you can create a datatable and add it to the Tables collection of a DataSet. Christian Graus - Microsoft MVP - C++

          J 1 Reply Last reply
          0
          • C Christian Graus

            A DataSet is a collection of DataTables, I'd assume you can create a datatable and add it to the Tables collection of a DataSet. Christian Graus - Microsoft MVP - C++

            J Offline
            J Offline
            JC Carmo
            wrote on last edited by
            #5

            Hi Christian, It's me again. I don't mean to be a drag, sorry about it, but I know how to connect to a dataSet in events such as form-load, but in this particular case, I'm a little lost, since the code I posted is part of teh code that filter values in comboboxes in a datagridview. Thanks a lot. JC. :)

            C 1 Reply Last reply
            0
            • J JC Carmo

              Hi Christian, It's me again. I don't mean to be a drag, sorry about it, but I know how to connect to a dataSet in events such as form-load, but in this particular case, I'm a little lost, since the code I posted is part of teh code that filter values in comboboxes in a datagridview. Thanks a lot. JC. :)

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              If you're copying an entire table, you can probably call it's Clone() method to create a copy and stuff it into a dataset. I'm guessing here tho. Why are you manipulating datasets and tables like this ? Christian Graus - Microsoft MVP - C++

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups