[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. :sick:
Re: [2008] Need held on my Datagrid
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.
Re: [2008] Need held on my Datagrid
Could you give me an example of this on how to add rownumber column jm?
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
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?
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"
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.
Re: [2008] Need held on my Datagrid
Quote:
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? :rolleyes:
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.
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.
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...:)
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?
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.
Re: [2008] Need held on my Datagrid
Quote:
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.
Quote:
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...:)