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. Visual Basic
  4. DataGrid in .Net

DataGrid in .Net

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcssasp-net
11 Posts 3 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.
  • B Offline
    B Offline
    Britnt7
    wrote on last edited by
    #1

    I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net

    H N 2 Replies Last reply
    0
    • B Britnt7

      I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net

      H Offline
      H Offline
      HarryBo
      wrote on last edited by
      #2

      Dim oConn As New OleDbConnection Dim oCmd As New OleDbCommand Some thing like this: Dim oDS As New DataSet Dim oDSNew As New DataSet Dim oDA As New OleDbDataAdapter(oCmd) Dim oCol As New DataColumn Dim oCol2 As New DataColumn Dim oCol3 As New DataColumn Dim oRows As DataRow Dim oTable As New DataTable oConn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HealthandSafety;Data Source=." oConn.Open() oCmd.CommandType = CommandType.Text oCmd.Connection = oConn oCmd.CommandText = "SELECT * FROM HSDocumentFloorZone" oDA.Fill(oDS) With oDS.Tables(0) oCol = .Columns(1) oCol2 = .Columns(3) oCol3 = .Columns(5) End With oDS.Tables(0).Columns.Clear() oDS.Clear() oDS.Dispose() With oTable .Columns.Add(oCol) .Columns.Add(oCol2) .Columns.Add(oCol3) End With oDSNew.Tables.Add(oTable) With DataGrid1 .DataSource = oDSNew End With Many Thanks Harry

      1 Reply Last reply
      0
      • B Britnt7

        I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net

        N Offline
        N Offline
        Nick Seng
        wrote on last edited by
        #3

        Manually add a mapping to those specific columns by adding columnstyles to your datagrid. The columnstyles are accesible through the TableStyle property at design-time. Note: you will also have to map the TableStyle to your table


        "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

        B 1 Reply Last reply
        0
        • N Nick Seng

          Manually add a mapping to those specific columns by adding columnstyles to your datagrid. The columnstyles are accesible through the TableStyle property at design-time. Note: you will also have to map the TableStyle to your table


          "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

          B Offline
          B Offline
          Britnt7
          wrote on last edited by
          #4

          What would be the mapping name? The database is Address and the table is ADDDAT. The combo box only displays none and I tried typing in Address.ADDDAT but nothing happened. Do you know where I can find some examples of this? Thanks. Beginner in ASP.Net and VB.Net

          N 1 Reply Last reply
          0
          • B Britnt7

            What would be the mapping name? The database is Address and the table is ADDDAT. The combo box only displays none and I tried typing in Address.ADDDAT but nothing happened. Do you know where I can find some examples of this? Thanks. Beginner in ASP.Net and VB.Net

            N Offline
            N Offline
            Nick Seng
            wrote on last edited by
            #5

            Let's say I have a table named "user" and columns "name","sex", "address" in that table, and I want to display only name and sex in the datagrid. Therefore, the mapping name for the tablestyle would be "user", and I'll create two columnstyles with the mapping name "name" and "sex". HTH.


            "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

            B 1 Reply Last reply
            0
            • N Nick Seng

              Let's say I have a table named "user" and columns "name","sex", "address" in that table, and I want to display only name and sex in the datagrid. Therefore, the mapping name for the tablestyle would be "user", and I'll create two columnstyles with the mapping name "name" and "sex". HTH.


              "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

              B Offline
              B Offline
              Britnt7
              wrote on last edited by
              #6

              What I have done was mapped the table style to Address and mapped the columns to First, Last, and Work (using First, Last, and Work). This all seems to make sense to me but nothing seems to happen when I load the form. Is there something that I might be missing? Do I have to programatically fill the datagrid using the new tablestyle? Thanks. Beginner in ASP.Net and VB.Net

              N 1 Reply Last reply
              0
              • B Britnt7

                What I have done was mapped the table style to Address and mapped the columns to First, Last, and Work (using First, Last, and Work). This all seems to make sense to me but nothing seems to happen when I load the form. Is there something that I might be missing? Do I have to programatically fill the datagrid using the new tablestyle? Thanks. Beginner in ASP.Net and VB.Net

                N Offline
                N Offline
                Nick Seng
                wrote on last edited by
                #7

                That's weird. Well this is how I do it. In Design View, I drag the datagrid onto the form. Then on the property grid, click on the ellipse for the TableStyle property. A dialog box will appear. Click Add to add a tablestyle, set the Mapping Name property to your tablename, then click on the ellipse for the gridcolumnstyle property. Another dialog box will appear. Click on Add to add a columnstyle, then set the mapping name to the column you want to show. Repeat this last bit for each column.


                "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                B 1 Reply Last reply
                0
                • N Nick Seng

                  That's weird. Well this is how I do it. In Design View, I drag the datagrid onto the form. Then on the property grid, click on the ellipse for the TableStyle property. A dialog box will appear. Click Add to add a tablestyle, set the Mapping Name property to your tablename, then click on the ellipse for the gridcolumnstyle property. Another dialog box will appear. Click on Add to add a columnstyle, then set the mapping name to the column you want to show. Repeat this last bit for each column.


                  "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                  B Offline
                  B Offline
                  Britnt7
                  wrote on last edited by
                  #8

                  So there is nothing to do programatically? I have done the above steps and rechecked them but nothing still happens. Would you mind me zipping up my project and emailing it too you to see if you see the problem? I'm sure there is something that I am doing wrong. Thanks. Beginner in ASP.Net and VB.Net

                  N 1 Reply Last reply
                  0
                  • B Britnt7

                    So there is nothing to do programatically? I have done the above steps and rechecked them but nothing still happens. Would you mind me zipping up my project and emailing it too you to see if you see the problem? I'm sure there is something that I am doing wrong. Thanks. Beginner in ASP.Net and VB.Net

                    N Offline
                    N Offline
                    Nick Seng
                    wrote on last edited by
                    #9

                    Sure, go ahead.


                    "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                    B 1 Reply Last reply
                    0
                    • N Nick Seng

                      Sure, go ahead.


                      "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                      B Offline
                      B Offline
                      Britnt7
                      wrote on last edited by
                      #10

                      nick.seng@gmail.com Is this your email? I tried to send you a zip file called Address.zip but it came back as illegal attachment. If you want you can contact me via email directly, timothy@myactv.net. Thanks. Beginner in ASP.Net and VB.Net

                      N 1 Reply Last reply
                      0
                      • B Britnt7

                        nick.seng@gmail.com Is this your email? I tried to send you a zip file called Address.zip but it came back as illegal attachment. If you want you can contact me via email directly, timothy@myactv.net. Thanks. Beginner in ASP.Net and VB.Net

                        N Offline
                        N Offline
                        Nick Seng
                        wrote on last edited by
                        #11

                        Sorry for the late reply, time-zone difference and all. if the gmail doesn't work, send it to catpainter79 AT yahoo DOT com


                        "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                        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