How to view a table using the Data Grid View
-
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
-
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
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.
-
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
-
Hi, guy, there are codes bellow, you can try to bind GridView firstly. dataGridView1.DataSource = datatable1; dataGridView1.DataBind();
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
-
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.
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
-
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
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.