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. How to view a table using the Data Grid View

How to view a table using the Data Grid View

Scheduled Pinned Locked Moved C#
csharpcsstutorialquestion
6 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.
  • J Offline
    J Offline
    Jeff Patterson
    wrote on last edited by
    #1

    I have been struggling for a long while now trying to get a simple table to display in a data grid view on a C# windows form.   I believe I am doing something wrong but...I can't see where I am straying. All of the examples and sample files essentially tell me to create a new data source and then drag the table I want to use onto the forms designer and wa-la! :confused: but it isn't working for me. I can preview the data in the table and I see the records there, but running the form shows a blank grid and a -1 shows when I click in the grid. Can anyone lend some advice? I am using VS2008 SP1 and Access 2007 on a Windows7 machine. I also tried with the exact same results SQLExpress 2008. Jeff

    S C 2 Replies Last reply
    0
    • J Jeff Patterson

      I have been struggling for a long while now trying to get a simple table to display in a data grid view on a C# windows form.   I believe I am doing something wrong but...I can't see where I am straying. All of the examples and sample files essentially tell me to create a new data source and then drag the table I want to use onto the forms designer and wa-la! :confused: but it isn't working for me. I can preview the data in the table and I see the records there, but running the form shows a blank grid and a -1 shows when I click in the grid. Can anyone lend some advice? I am using VS2008 SP1 and Access 2007 on a Windows7 machine. I also tried with the exact same results SQLExpress 2008. Jeff

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, maybe the bind-command is missing within the source code. Could you post a bit of your code? Maybe the code within the designer.cs where the grid is constructed. For a detailed example have a look here: http://69.10.233.10/KB/vb/DataGridViewEditForm.aspx[^] Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      J 1 Reply Last reply
      0
      • J Jeff Patterson

        I have been struggling for a long while now trying to get a simple table to display in a data grid view on a C# windows form.   I believe I am doing something wrong but...I can't see where I am straying. All of the examples and sample files essentially tell me to create a new data source and then drag the table I want to use onto the forms designer and wa-la! :confused: but it isn't working for me. I can preview the data in the table and I see the records there, but running the form shows a blank grid and a -1 shows when I click in the grid. Can anyone lend some advice? I am using VS2008 SP1 and Access 2007 on a Windows7 machine. I also tried with the exact same results SQLExpress 2008. Jeff

        C Offline
        C Offline
        carlecomm
        wrote on last edited by
        #3

        Hi, guy, there are codes bellow, you can try to bind GridView firstly. dataGridView1.DataSource = datatable1; dataGridView1.DataBind();

        J 1 Reply Last reply
        0
        • C carlecomm

          Hi, guy, there are codes bellow, you can try to bind GridView firstly. dataGridView1.DataSource = datatable1; dataGridView1.DataBind();

          J Offline
          J Offline
          Jeff Patterson
          wrote on last edited by
          #4

          Thanks for the advice, but... I am not sure how to implement your samples. I am using the "built in" features that generate the code automatically and it looks like the lines you suggest are being called... except for the DataBind() function. it doesn't appear to be an option for this grid control. :( Thanks again for the help Jeff

          1 Reply Last reply
          0
          • S SeMartens

            Hi, maybe the bind-command is missing within the source code. Could you post a bit of your code? Maybe the code within the designer.cs where the grid is constructed. For a detailed example have a look here: http://69.10.233.10/KB/vb/DataGridViewEditForm.aspx[^] Regards Sebastian

            It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

            J Offline
            J Offline
            Jeff Patterson
            wrote on last edited by
            #5

            If I understand correctly, below is the code from the frmMain.designer.cs file. I am a bit confused over this whole thing as to what does what and why. If you have a good reference resource that might help me I would appreciate it, so that I don't use too much of your time. I have Murach's C#2008 and SQL Server 2008 for Developers as well as a number of older MS Press books for C#. The MSPress books are all quite dated and a bit sparse for database information. <pre>// // tasksBindingSource // this.tasksBindingSource.DataMember = "Tasks"; this.tasksBindingSource.DataSource = this.timeSheetDataSet; ... ... ... // // tasksDataGridView // this.tasksDataGridView.AutoGenerateColumns = false; this.tasksDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.tasksDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, this.dataGridViewTextBoxColumn3}); this.tasksDataGridView.DataSource = this.tasksBindingSource; this.tasksDataGridView.Location = new System.Drawing.Point(36, 195); this.tasksDataGridView.Name = "tasksDataGridView"; ... ...</pre> Thanks for the time and the help. Jeff

            S 1 Reply Last reply
            0
            • J Jeff Patterson

              If I understand correctly, below is the code from the frmMain.designer.cs file. I am a bit confused over this whole thing as to what does what and why. If you have a good reference resource that might help me I would appreciate it, so that I don't use too much of your time. I have Murach's C#2008 and SQL Server 2008 for Developers as well as a number of older MS Press books for C#. The MSPress books are all quite dated and a bit sparse for database information. <pre>// // tasksBindingSource // this.tasksBindingSource.DataMember = "Tasks"; this.tasksBindingSource.DataSource = this.timeSheetDataSet; ... ... ... // // tasksDataGridView // this.tasksDataGridView.AutoGenerateColumns = false; this.tasksDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.tasksDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, this.dataGridViewTextBoxColumn3}); this.tasksDataGridView.DataSource = this.tasksBindingSource; this.tasksDataGridView.Location = new System.Drawing.Point(36, 195); this.tasksDataGridView.Name = "tasksDataGridView"; ... ...</pre> Thanks for the time and the help. Jeff

              S Offline
              S Offline
              SeMartens
              wrote on last edited by
              #6

              Hi Jeff, I was searching the missing DataBind()-method call as carlecomm already suggested. So I guess using the answer of carlecomm it worked. There are plenty of examples around but I would suggest you take a look at the msdn sample: http://msdn.microsoft.com/en-us/library/1x64c23x.aspx[^] Regards Sebastian

              It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

              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