|
-
Oct 31st, 2007, 12:06 PM
#1
Thread Starter
Member
Sorting Dataset & Datgridview
Hi,
I'm just wondering if someone can help please me out with the issue below.
In the Form_load
BindingSource1.DataSource = Pb_guyanaDataSet.Tables("BB_Section")
DataGridView1.DataSource = BindingSource1.DataSource
DataGridView1.Refresh()
When I click on the up button. I'm updating the sequence number of the selected row and the previous row and refresh the datagrid. My objective is to move the selected row one row up
The first time it works but since the dataset has not been refresh with the sorting, the second time it does not work
E.g
My dataset is as follows when I load the form as well as the datagridview
section 1 seq1
section2 seq2
section3 seq3
section4 seq4
I select section4 and click on up
My dataset
section 1 seq1
section2 seq2
section3 seq4
section4 seq3
My Datagridview
section 1 seq1
section2 seq2
section4 seq3
section3 seq4
If I section4 again and click on the up button, the sequence get all messed up
because on the datagridview, index 3 has section4 but in the dataset it's section3.
Can someone pls tell me how to solve this issue.
Below is my code in the up buttom
Dim CurBookID, CurSection, CurSequence As Integer
Dim PrevBookid, PrevSection, PrevSequence, PrevNewSeq As Integer
Dim PrevName, CurName As String
Dim CurIndex, PrevIndex As Integer
Dim cm As CurrencyManager = CType(DataGridView1.BindingContext(DataGridView1.DataSource), CurrencyManager)
Dim dr As DataRow
dr = Pb_guyanaDataSet.Tables("BB_SECTION").Rows(cm.Position)
CurIndex = cm.Position
If (CurIndex >= 1) Then
PrevIndex = CurIndex - 1
CurBookID = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(DataGridView1.CurrentRow.Index).Item("BookID").ToSt ring()).Trim
CurSection = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(DataGridView1.CurrentRow.Index).Item("SectionID").T oString()).Trim
CurSequence = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(DataGridView1.CurrentRow.Index).Item("Sequence").To String()).Trim
CurName = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(DataGridView1.CurrentRow.Index).Item("SectionName") .ToString()).Trim
PrevBookid = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(PrevIndex).Item("BookID").ToString()).Trim
PrevSection = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(PrevIndex).Item("SectionID").ToString()).Trim
PrevSequence = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(PrevIndex).Item("Sequence").ToString()).Trim
PrevName = (Pb_guyanaDataSet.Tables.Item("BB_Section").Rows(PrevIndex).Item("SectionName").ToString()).Trim
PrevNewSeq = PrevSequence + 1
NewConn.Open()
Dim vsqlstr As String
vsqlstr = "Update BB_Section set Sequence = " & CurIndex & " where BookID = " & CurBookID & " and SectionID = " & CurSection
Dim db_command As New SqlCommand(vsqlstr, NewConn)
db_command.ExecuteScalar()
vsqlstr = "Update BB_Section set Sequence = " & PrevNewSeq & " where BookID = " & PrevBookid & " and SectionID = " & PrevSection
Dim db_command1 As New SqlCommand(vsqlstr, NewConn)
db_command1.ExecuteScalar()
NewConn.Close()
Me.BB_SectionTableAdapter.Fill(Me.Pb_guyanaDataSet.BB_Section)
DataGridView1.Refresh()
DataGridView1.Sort(DataGridView1.Columns(3), System.ComponentModel.ListSortDirection.Ascending)
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
|