Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I know if I use the following line that my data set will be sorted by the column I want.

 

dsEvents.Tables("Events").DefaultView.Sort = "RunTime"

 

Here is how I am getting the data

 

               tbEventName.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("EventName")
               tbCommand.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("Command")
               dtpTime.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("RunTime")
               cmbBox.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("ComPort")

               Days(dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("Days"))

 

Then the DatagridView Displays the data correctly. If the user changes the sort in the DataGridView the Data I want to retrieve from the DataGridView is messed up. So I have two questions.

 

1. How can I sort my DataSet when the sort changes on the DataGridView

 

2. How do I disable the sort on the DataGridView

 

Thanks

 

ZeroEffect

Edited by ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted

I don't know for the first question, but for the second this might help:

 

  For i As Integer = 0 To datagridview.Columns.Count - 1
               datagridview.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
  Next

Posted

Thanks PUIU that helped.

 

Now I have figured out how to get data from a DataGridView row.

 

DataGridView.Rows(DataGridView.CurrentRow.Index).Cells(i).Value
'i is the number of the column starting with 0

 

So this is good I have my data loaded into the DGV and sorted the way I want. Now I have a new issue. When I go to update a row in the Dataset the wrong row is updating. I have tried resorting by ID which should put the DS back into it orignal order. Then sort back after the changes have been made. But if I have the DS sorted by a different column then loaded shouldn't that change the row index to?

 

example

 

rows before sort are

 

4 (index 0)

1

3

2 (index 3)

 

After sort

 

1 (index 0)

2

3

4 (index 3)

 

After my sort the orignal index number seems to follow the rows. Is this how this works or am I missing something?

 

Thanks for any help you may provide.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...