473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrigView Sorting Problem - Experts HELP Please

12 New Member
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 2164
Dököll
2,364 Recognized Expert Top Contributor
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
1847
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
2515
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
2362
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
4218
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
25422
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
11335
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
3026
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
1404
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
955
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...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.