בעייה משונה עם DataGridViewCell

../images/Emo41.gif בעייה משונה עם DataGridViewCell

יש לי control שמימשתי שיורש מ-DataGridView שאני עושה בו ולידציה על הנתונים. במקרה שהוכנס נתון לא נכון לאחד הcells ולוחצים על TAB כדי לעבור לCELL הבא אני עושה override ל-ValidateCell ושם אני משנה את הצבע של הCELL בדרך הבאה:
cell.Style.BackColor = ControlsUtils.ERROR_COLOR; cell.Style.SelectionBackColor = ControlsUtils.ERROR_COLOR;​
הבעייה היא שלא משנה מה אני עושה הצבע של התא נשאר הצבע הדיפולטי. התנאי היחיד שמפריע הוא שאנחנו צריכים להשאר באותו CELL במידה והולידציה נכשלה. מה שניסיתי לעשות ולא עבד: 1. לבצע את הpaint בעצמנו 2. לנסות לחזור לCELL שלא עבר ולידציה (יתכן ולא עשיתי את זה נכון) אשמח לשמוע אם יש למישהו ידע איך לעשות כזה דבר
 

yairov

New member
תגובה

אני מאמין ש-ValidateCell זה אירוע שמתבצע ב-Server והטאב שאתה לוחץ זה אירוע שמתרחש ב-Client. תבדוק שימוש ב-asp.net validators שיתנו לך פיתרון חלקי לבעיה או תממש בעצמך סקריפט צד לקוח.
 
מצאתי את הפתרון

תודה, הרכיב הוא WinForms פתרתי את הבעיה בעזרת Win32 לחיצה מחדש על הCell
[DllImport ( "user32.dll" )] public static extern void mouse_event ( MouseEventType dwFlags, int dx, int dy, int cButtons, int dwExtraInfo ); [DllImport ( "user32" )] public static extern int SetCursorPos ( int x, int y ); public enum MouseEventType : int { LeftDown = 0x02, LeftUp = 0x04, RightDown = 0x08, RightUp = 0x10 } if (EditingControl != null) { Point p = EditingControl.PointToScreen ( new Point ( 0, 0 ) ); _iErrorCellX = p.X + 10; _iErrorCellY = p.Y + 10; } SetCursorPos ( _iErrorCellX, _iErrorCellY ); mouse_event ( MouseEventType.LeftDown, _iErrorCellX, _iErrorCellY, 0, 0 ); mouse_event ( MouseEventType.LeftUp, _iErrorCellX, _iErrorCellY, 0, 0 );​
 
למעלה