|
-
May 22nd, 2008, 04:33 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED][2008] Need held on my Datagrid
Elow everyone I just want to know how to get the first five row on my datagrid and put in on a textboxes. I just got the First row but how can i get the next succeding row? I have my code upon getting my first row, how about the reamining 5 rows? Here is my code below
Code:
myConnection.Open()
myAdapter.Fill(myDataset, "SalesMonitor")
DataGridView1.DataSource = myDataset.Tables("SalesMonitor")
Dim myReader As System.Data.SqlClient.SqlDataReader
myReader = myCommand.ExecuteReader()
Dim nCnt As Integer
nCnt = 0
While myReader.Read()
nCnt = nCnt + 1
If nCnt = 1 Then
txtStore1.Text = myReader.GetString(0)
lblAPQTY1.Text = myReader.GetDecimal(1)
lblAPAMT1.Text = myReader.GetDecimal(2)
lblMCQTY1.Text = myReader.GetDecimal(3)
lblMCAMT1.Text = myReader.GetDecimal(4)
lblATSQTY1.Text = myReader.GetDecimal(5)
lblATSAMT1.Text = myReader.GetDecimal(6)
lblFURQTY1.Text = myReader.GetDecimal(7)
lblFURAMT1.Text = myReader.GetDecimal(8)
lblPARTSQTY1.Text = myReader.GetDecimal(9)
lblPARTSAMT1.Text = myReader.GetDecimal(10)
lblDate1.Text = myReader.GetDateTime(11)
End If
End While
myReader.Close()
myConnection.Close()
How can i get the next four succeding row on my datagrid? Could anyone help me pls??? I really need it badly...Thanks in advance guys and have a pleasant morning 2 everyone.
Last edited by shyguyjeff; May 25th, 2008 at 11:42 PM.
-
May 22nd, 2008, 10:29 PM
#2
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
-
May 23rd, 2008, 12:26 AM
#3
Re: [2008] Need held on my Datagrid
Add a RowNumber column to your DataTable and then filter on that. You'll have to create at least one DataView in order to have two different filters.
If you're using SQL Server is has a ROW_NUMBER function that can add the column to the result set.
-
May 23rd, 2008, 12:38 AM
#4
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
Could you give me an example of this on how to add rownumber column jm?
-
May 23rd, 2008, 01:28 AM
#5
Re: [2008] Need held on my Datagrid
Are you using SQL Server 2005? If so I believe it would be like this:
vb.net Code:
SELECT *, ROW_NUMBER() OVER (ORDER BY ID) AS RowNumber FROM MyTable
-
May 23rd, 2008, 01:38 AM
#6
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
i did not use SQL 2005 jm...how about just adding up RowNumber column on my DataTable and then filter it jm?
-
May 23rd, 2008, 01:46 AM
#7
Re: [2008] Need held on my Datagrid
vb.net Code:
myDataTable.Columns.Add("RowNumber") For rowIndex As Integer = 0 To myDataTable.Rows.Count - 1 Step 1 myDataTable.Rows(rowIndex)("RowNumber") = rowIndex + 1 Next rowindex Me.BindingSource1.DataSource = myDataTable Me.BindingSource1.Filter = "RowNumber <= 5" Me.BindingSource2.DataSource = New DataView(myDataTable) Me.BindingSource2.Filter = "RowNumber > 5"
-
May 23rd, 2008, 01:58 AM
#8
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
i receive a blue highlighted text jm saying that BindingSource1 and BindingSource2 is not a member of Form1.
-
May 23rd, 2008, 02:09 AM
#9
Re: [2008] Need held on my Datagrid
 Originally Posted by shyguyjeff
i receive a blue highlighted text jm saying that BindingSource1 and BindingSource2 is not a member of Form1.
Would you like me to add them for you?
-
May 23rd, 2008, 02:28 AM
#10
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
I could not get what the comments saying jm because Datagrid in vb.net 2003 is so very different on the vb2008 datagrid, there the datagrid can be easily bind but in vb2008 it's not. Sorry if I ask so newbie question.
Last edited by shyguyjeff; May 23rd, 2008 at 03:37 AM.
-
May 23rd, 2008, 02:53 AM
#11
Re: [2008] Need held on my Datagrid
Binding data to a DataGridView in VB 2008 is no more difficult than binding data to a DataGrid in VB.NET 2003. They both have a DataSource property that you assign your list to. That's it. In VB 2008 it is generally preferable to use a BindingSource when data-binding as it makes various tasks easier. It also has a DataSource property. You bind your list to the BindingSource and your BindingSource to the grid. Two steps instead of one but they both involve simply setting a DataSource property.
-
May 23rd, 2008, 03:39 AM
#12
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
ahhhh...okies jm...i just misunderstood the comments jm...now i already...Again a million thanks to jm..Have a nice day and God Bless...
-
May 23rd, 2008, 04:36 AM
#13
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
I forgot to ask jm...How can I call the rows and put it on the textbox? on my first post I already got the First row and successfully put it on the textbox my problem is that on the 2 up to fifth row how can I got it?
-
May 23rd, 2008, 04:55 AM
#14
Re: [2008] Need held on my Datagrid
You should be binding the data, which is why I used a BindingSource in my example. Again, it's exactly the same as in .NET 1.x: you bind the list to the controls via the DataBindings collection.
-
May 25th, 2008, 07:48 PM
#15
Thread Starter
Hyperactive Member
Re: [2008] Need held on my Datagrid
 Originally Posted by jmcilhinney
You should be binding the data, which is why I used a BindingSource in my example. Again, it's exactly the same as in .NET 1.x: you bind the list to the controls via the DataBindings collection.
Thanks jm...But my problem is that don't know yet how to bind Data using Databindings. I used listview last on my vb.net 2003 that why im not yet too familiar with the datagridview now. Could you give at least one example jm like for example on my datagridview, there are five columns then 5 rows this is the following format.
Storename MC AP Total
Store1 1000 2000 3000
Store2 2000 2000 4000
Store3 1500 2000 3500
Store4 3000 2000 5000
Store5 2000 2500 4500
I want to get it jm and put it on my textbox. Like for example I want to get the textbox1.text = row(1) column(1),textbox2.text = row(1) column(2) Is it possible jm?Thanks again jm..Have a nice day..God Bless...
Last edited by shyguyjeff; May 25th, 2008 at 09:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|