473,287 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

DataGrigView Sorting Problem - Experts HELP Please

Hi all,
i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps:
1. i have a datagridview with two columns (LoginName,UserName)
2. the datagridview sorting is set to automatic, so when i click on the column header is sorts well.
3. i put in an event handler for the CellEndEdit Event, so whenever the user of the program changes the content of a cell in the LoginName column - the event handle code - checks if there is a similar name in the login names, or if the program user had input an empty string (Null) instead of a valid name, if both checks passed the user table is updated with the new login name.
4. because this process should be done before passing the cursor to a new cell in the grid, i keep the value of the row where the cell under checking belongs in a text box, lets say row (3), and i do all the checks in the beginning of the CellEndEdit Event refering to the text box row number, if everything is ok, the code first applies the update to the table and then changes the text box value to the current cell value.
5. MY PROBLEM IS, once i change the cell value, the grid sorting takes effect immediatly giving me wrong references.
Please see my Code below , i think it is difficult to descibe.

' DGusers1 IS MY DATAGRIDVIEW
' I PUT IN THIS EVENT HANDLE TO STOP THE DATAGRID SORTING BUT IT DOESNOT WORK

Private Sub DGUsers1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventAr gs) Handles DGUsers1.CellBeginEdit
DGUsers1.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
DGUsers1.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
End Sub


Private Sub DGUsers1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGUsers1.CellEndEdit

Dim x As Integer
Dim xx As String
Dim xy As String
Dim xz As Integer
Dim xz1 As Object
Dim xz2 As Object
Dim xz3 As Integer
Dim xz4 As Object
Dim xy4 As Object
Dim xz5 As Integer
Dim vx As Integer
' I AM TRYING HERE TO STOP THE DATAGRID SORTING ALSO BUT IT DOESNOT WORK
DGUsers1.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
DGUsers1.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable

' HERE I GET THE VALUE OF THE DATAGRIDROW -FOR THE CELL UNDER CHECKING -FROM A TEXT BOX NAMED DGusersrowid. THE CELL UNDER CHECKING IS THE CELL I HAVE JUST LEFT TO CALLTHIS PROCEDURE.

'HERE IS MY PROBLEM

Dim Valx As Object
Dim Valy As Object

Valx = DGUsers1.Rows(DGusersRowID.Text).Cells(1).Value
Valy = DGUsers1.Rows(DGusersRowID.Text).Cells(2).Value

' THE VALX AND VALY VALUES REFLECTS THE VALUES OF THE LOGIN NAME AND USER NAME . ONCE I LEAVE THE CELL AFTER CHANGING ITS VALUE, AND BEFORE THIS SUB RUNS, THE DATAGRID SORTS ITSELF , SO I GET THE VALUE OF THE LOGIN NAME AT ROW REPRESENTING DGusersRowID.Text BUT AFTER THE SORTING HAD TOOK EFFECT.
IN BRIEF, I NEED THE SORTING BUT ON THE OTHER HAND I GET WRONG VALUES.


OleDbConnection1.Open()
OleDbDataAdapter1.UpdateCommand.CommandText = "UPDATE USERS SET LOGINAME = '" & LogName.Text & "', USERNAME = '" & Valy & "', EPROFID = " & ComboBox1.SelectedValue & ", EMAIL = '" & Email.Text & "', PHONE = '" & Phone.Text & "' WHERE (USERID = " & UserID.Text & ")"
OleDbDataAdapter1.UpdateCommand.ExecuteNonQuery()
OleDbConnection1.Close()

'HERE I CHANGE THE TEXTBOX CELL VALUE TO THE CURRENT CELL VALUE
x = DGUsers1.CurrentCell.RowIndex

DGusersRowID.Text = x

xx = DGUsers1.Rows(x).Cells(1).Value
Dim mychkxx As Boolean
mychkxx = IsDBNull(xx)
If mychkxx = True Then
DGUsers1.Rows(x).Cells(1).Value = LogName.Text
xx = DGUsers1.Rows(x).Cells(1).Value
End If
xy = DGUsers1.Rows(x).Cells(2).Value
mychkxx = IsDBNull(xy)
If mychkxx = True Then
DGUsers1.Rows(x).Cells(2).Value = UserName.Text
xy = DGUsers1.Rows(x).Cells(2).Value
End If
xz = DGUsers1.Rows(x).Cells(0).Value
xz1 = DGUsers1.Rows(x).Cells(5).Value
xz2 = DGUsers1.Rows(x).Cells(6).Value
xz3 = DGUsers1.Rows(x).Cells(4).Value
If IsDBNull(xz1) = True Then
xz1 = ""
End If
If IsDBNull(xz2) = True Then
xz2 = ""
End If
' HERE I FILL UP SOME OTHER TEXT OXES WITH THE NEW VALUES
LogName.Text = xx
UserName.Text = xy
UserID.Text = xz
Email.Text = xz1
Phone.Text = xz2
ComboBox1.SelectedValue = xz3

DupMsg.Text = 0
GetData()


start:
DsUserEdit1.Tables.Remove("LNDupVal")

Beg:
End Sub
Sep 15 '07 #1
1 2152
Dököll
2,364 Expert 2GB
I am not sure how to do this Sir Yasser, I did find related information I thought might help: http://www.thescripts.com/forum/thre...w+Sorting.html

Try link, see what you can accomplish, and stay tuned, experts here may see your note.

In a bit!
Sep 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: shalendra chhabra | last post by:
Hi, I just had a tryst with python. I was wondering if python is good enough to do this kind of job -- for it has extensive support of string and pattern matching, ordering and list handling. ...
4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
25
by: Allie | last post by:
How would I go about sorting this structure by title? typedef struct { char author; char title; char code; int hold; int loan; } LIBRARY;
2
by: jab3 | last post by:
Hello - I'm trying to implement a table that will allow the user to sort on each column, like many applicaitons that have tabular data (e-mail, song list, etc). It invovles grabbing the table,...
5
by: wtxwtx | last post by:
Hi, Someone said in 1970 that soring algorithm is so important that one of 4 CPU clocks spent on sorting on that time. Do you know who said that and in which page of what book? Thank you. ...
2
by: Stéphane Miqueu | last post by:
Hi, I sort my datagridview with : dgWrk.Sort(dgWrk.Columns(3),... and it works perfect. Now, I want it sorted on 2 columns. How did I do that ? I've try...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.