943,685 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3557
  • VB.NET RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 2nd, 2009
0

Re: Viewing Data in Datagrid

Try replacing:

Click to Expand / Collapse  Quote originally posted by bajanpoet ...
VB.NET Syntax (Toggle Plain Text)
  1. dgCustomers.DataSource = ds.DefaultViewManager
with
VB.NET Syntax (Toggle Plain Text)
  1. dgCustomers.DataSource = r
  2. dgCustomers.DataBind()

....
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 2nd, 2009
0

Re: Viewing Data in Datagrid

And I know that others are reading this, help us out here lol
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

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'.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 3rd, 2009
-1

Re: Viewing Data in Datagrid

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.
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

This is the code that worked for me.
VB Syntax (Toggle Plain Text)
  1. dgCustomers.DataSource = ds.Tables(0)
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 3rd, 2009
1

Re: Viewing Data in Datagrid

great!
Last edited by rapture; Feb 3rd, 2009 at 9:44 am.
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

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.....

VB.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

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.
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 3rd, 2009
0

Re: Viewing Data in Datagrid

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
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Visual Basic Employee Clock
Next Thread in VB.NET Forum Timeline: Procedure or function insertCashBook has too many arguments specified.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC