Viewing Data in Datagrid

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Viewing Data in Datagrid

 
0
  #11
Feb 2nd, 2009
Try replacing:

Originally Posted by bajanpoet View Post
  1. dgCustomers.DataSource = ds.DefaultViewManager
with
  1. dgCustomers.DataSource = r
  2. dgCustomers.DataBind()

....
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Viewing Data in Datagrid

 
0
  #12
Feb 2nd, 2009
And I know that others are reading this, help us out here lol
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
0
  #13
Feb 3rd, 2009
Sorry, couldn't get to this yesterday evening...

I tried the Databind() function, but VB says that Databind is not a member of the 'System.Windows.Forms.DataGridView'.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
-1
  #14
Feb 3rd, 2009
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!!!!
Last edited by 4advanced; Feb 3rd, 2009 at 8:56 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
0
  #15
Feb 3rd, 2009
It's not working. I've been doing everything people have requested from the time I asked for help. I know it's supposed to work, and I've already "checked the posts on the first page", thank you very much. I would appreciate that you do not insult my intelligence.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
0
  #16
Feb 3rd, 2009
This is the code that worked for me.
  1. dgCustomers.DataSource = ds.Tables(0)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Viewing Data in Datagrid

 
1
  #17
Feb 3rd, 2009
great!
Last edited by rapture; Feb 3rd, 2009 at 9:44 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
0
  #18
Feb 3rd, 2009
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.....

  1. Imports System.Data
  2.  
  3. Public Class Form2
  4.  
  5. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. 'Create a new dataset
  7. Dim _Dataset As DataSet = New DataSet
  8. 'Create a new datatable called "Customers"
  9. Dim _DataTable As DataTable = New DataTable("Customers")
  10.  
  11. 'Create some columns in the datatable
  12. Dim _Column As DataColumn = New DataColumn
  13. _Column.DataType = Type.GetType("System.Int32")
  14. _Column.ColumnName = "ID"
  15. _Column.AutoIncrement = True
  16. _Column.AutoIncrementSeed = 1
  17. _Column.AutoIncrementStep = 1
  18.  
  19. 'add the column to the datatable
  20. _DataTable.Columns.Add(_Column)
  21.  
  22. _Column = New DataColumn
  23. _Column.DataType = Type.GetType("System.String")
  24. _Column.ColumnName = "Name"
  25.  
  26. 'add the column to the datatable
  27. _DataTable.Columns.Add(_Column)
  28.  
  29.  
  30. 'add some rows to the datatable
  31. For iCnt As Integer = 1 To 10
  32. Dim _DataRow As DataRow = _DataTable.NewRow
  33. _DataRow.Item("Name") = String.Format("Name {0}", iCnt.ToString)
  34. _DataTable.Rows.Add(_DataRow)
  35. Next
  36.  
  37. Me.DataGridView1.DataSource = _DataTable
  38.  
  39.  
  40. End Sub
  41.  
  42. Private Sub cmdDataView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDataView.Click
  43. Dim _DataTableTemp As New DataTable
  44. _DataTableTemp = Me.DataGridView1.DataSource
  45. Dim _DataView As DataView = _DataTableTemp.DefaultView
  46. _DataView.Sort = "ID desc"
  47. Me.DataGridView1.DataSource = _DataView
  48. End Sub
  49.  
  50. End Class


hmmm.... slightly too late :=)
Last edited by 4advanced; Feb 3rd, 2009 at 9:52 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Viewing Data in Datagrid

 
0
  #19
Feb 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Viewing Data in Datagrid

 
0
  #20
Feb 3rd, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1850 | Replies: 22
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC