| | |
Viewing Data in Datagrid
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2007
Posts: 277
Reputation:
Solved Threads: 37
Try replacing:
•
•
•
•
withVB.NET Syntax (Toggle Plain Text)
dgCustomers.DataSource = ds.DefaultViewManager
VB.NET Syntax (Toggle Plain Text)
dgCustomers.DataSource = r dgCustomers.DataBind()
....
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
Databind() is a function which needs to be called when binding data to a datagrid in ASP.NET !
Only use datasource when binding in Windows.Forms solutions!
yourGrid.DataSource = yourDataSource
If you had checked the posts on the first page you would have found out the solution....it has been mentioned a few times before!!!!
Only use datasource when binding in Windows.Forms solutions!
yourGrid.DataSource = yourDataSource
If you had checked the posts on the first page you would have found out the solution....it has been mentioned a few times before!!!!
Last edited by 4advanced; Feb 3rd, 2009 at 8:56 am.
•
•
Join Date: Sep 2006
Posts: 90
Reputation:
Solved Threads: 0
This is the code that worked for me.
VB Syntax (Toggle Plain Text)
dgCustomers.DataSource = ds.Tables(0)
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
Euhh..... insulting your intelligence? Excuse me, that's not what i intended to mention.
Lets start over again. You are trying to view some table-data in a datagrid in a "windows application".
The data bound to the grid can be of different types. A dataset, a datatable, a dataview, a xml-file....you name it.....
If you use a dataset, you have to mention the datatable from the collection (dataset.Tables()) by number or name:
For example dataset.tables(0) or dataset.tables("Customers") if you ever attached a name to the table.
Try this example, its a form with 1 datagridview & 1 button called cmdDataView. If you load the form it will show 10 records and after clicking the button "cmdDataView" it will reload the datagrid with a descending sorted view of the data.
In the example I create also a _DataSet which isn't used at this particular moment.....
hmmm.... slightly too late :=)
Lets start over again. You are trying to view some table-data in a datagrid in a "windows application".
The data bound to the grid can be of different types. A dataset, a datatable, a dataview, a xml-file....you name it.....
If you use a dataset, you have to mention the datatable from the collection (dataset.Tables()) by number or name:
For example dataset.tables(0) or dataset.tables("Customers") if you ever attached a name to the table.
Try this example, its a form with 1 datagridview & 1 button called cmdDataView. If you load the form it will show 10 records and after clicking the button "cmdDataView" it will reload the datagrid with a descending sorted view of the data.
In the example I create also a _DataSet which isn't used at this particular moment.....
VB.NET Syntax (Toggle Plain Text)
Imports System.Data Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create a new dataset Dim _Dataset As DataSet = New DataSet 'Create a new datatable called "Customers" Dim _DataTable As DataTable = New DataTable("Customers") 'Create some columns in the datatable Dim _Column As DataColumn = New DataColumn _Column.DataType = Type.GetType("System.Int32") _Column.ColumnName = "ID" _Column.AutoIncrement = True _Column.AutoIncrementSeed = 1 _Column.AutoIncrementStep = 1 'add the column to the datatable _DataTable.Columns.Add(_Column) _Column = New DataColumn _Column.DataType = Type.GetType("System.String") _Column.ColumnName = "Name" 'add the column to the datatable _DataTable.Columns.Add(_Column) 'add some rows to the datatable For iCnt As Integer = 1 To 10 Dim _DataRow As DataRow = _DataTable.NewRow _DataRow.Item("Name") = String.Format("Name {0}", iCnt.ToString) _DataTable.Rows.Add(_DataRow) Next Me.DataGridView1.DataSource = _DataTable End Sub Private Sub cmdDataView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDataView.Click Dim _DataTableTemp As New DataTable _DataTableTemp = Me.DataGridView1.DataSource Dim _DataView As DataView = _DataTableTemp.DefaultView _DataView.Sort = "ID desc" Me.DataGridView1.DataSource = _DataView End Sub End Class
hmmm.... slightly too late :=)
Last edited by 4advanced; Feb 3rd, 2009 at 9:52 am.
•
•
Join Date: Jul 2007
Posts: 277
Reputation:
Solved Threads: 37
4Advanced,
I struggle with this problem when working with international boards. I think what struck him was your use of exclamation points. It seemed in the thread like you were upset and/or dealing with someone stupid. What I have found mostly is that it's excitement, but not always negative especially from other countries than my own. It's hard to convey in a post if your feeling is such.
Thank you for your help, soon or late. It'll help the next person searching.
I struggle with this problem when working with international boards. I think what struck him was your use of exclamation points. It seemed in the thread like you were upset and/or dealing with someone stupid. What I have found mostly is that it's excitement, but not always negative especially from other countries than my own. It's hard to convey in a post if your feeling is such.
Thank you for your help, soon or late. It'll help the next person searching.
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
Rapture,
Thank you for your clarifying words. What you describe is exactly what I was thinking about. Exclamation points are a real pain in the *** sometimes but they do give some expression to the typed text. In The Netherlands we have a phrase which declares these kind of interpretations " The soup is never been eaten thát hot as it is being served" (if translated well :=) )
Kind regards,
Richard
The Netherlands
Thank you for your clarifying words. What you describe is exactly what I was thinking about. Exclamation points are a real pain in the *** sometimes but they do give some expression to the typed text. In The Netherlands we have a phrase which declares these kind of interpretations " The soup is never been eaten thát hot as it is being served" (if translated well :=) )
Kind regards,
Richard
The Netherlands
![]() |
Similar Threads
- Search Access Records (VB.NET)
- how to display data from db (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Visual Basic Employee Clock
- Next Thread: Procedure or function insertCashBook has too many arguments specified.
Views: 1851 | Replies: 22
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2008 access advanced application array basic beginner browser button buttons center class click client code combo convert cuesent data database datagrid datagridview date datetimepicker design designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function html images lib listview map mobile module msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read refresh regex richtextbox right-to-left save search serial settings shutdown socket sorting sqldatbase sqlserver studio temperature textbox timer timespan transparency txttoxmlconverter usercontol validation vb vb.net vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms winsock wpf wrapingcode xml year





