Click here to Skip to main content
16,012,843 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: installation issue of dot net 2005 Pin
Pete O'Hanlon11-Sep-08 22:11
mvePete O'Hanlon11-Sep-08 22:11 
GeneralHelp required in SQL query Pin
khalidd11-Sep-08 0:06
khalidd11-Sep-08 0:06 
GeneralRe: Help required in SQL query Pin
Pete O'Hanlon11-Sep-08 0:55
mvePete O'Hanlon11-Sep-08 0:55 
GeneralRe: Help required in SQL query Pin
Paul Conrad11-Sep-08 6:30
professionalPaul Conrad11-Sep-08 6:30 
QuestionInstallation of VisualStudio 2008 Pin
yadlaprasad10-Sep-08 2:10
yadlaprasad10-Sep-08 2:10 
AnswerRe: Installation of VisualStudio 2008 Pin
Pete O'Hanlon10-Sep-08 2:27
mvePete O'Hanlon10-Sep-08 2:27 
AnswerRe: Installation of VisualStudio 2008 Pin
John_Adams12-Sep-08 3:29
John_Adams12-Sep-08 3:29 
QuestionChange cell color in a DataGridView? Pin
Gregory Gadow9-Sep-08 7:07
Gregory Gadow9-Sep-08 7:07 
I have been working on a custom DataGridView which will be used in unbound mode. I have had a problem where, if the user edits a cell with text longer than allowed by the database, the text is truncated when it is saved back to the database.

The following OnCellValidating method is my attempt to validate the length of cell text. The idea is that if the new text is longer than allowed by the database, the cell changes its background color, a message is given and the user cannot proceed off the cell until valid data is provided. Here is the code:

VB
 1: Protected Overrides Sub OnCellValidating(ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs)
 2:     Dim Col As DataGridViewColumn = Me.Columns(e.ColumnIndex)
 3:     Dim FD As FieldDescriptor = TryCast(Col.Tag, FieldDescriptor)
 4: 
 5:     If Me.Rows(e.RowIndex).Cells(e.ColumnIndex) IsNot Nothing Then
 6:         Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Col.CellTemplate.Style.BackColor
 7:     End If
 8: 
 9:     If Col.ReadOnly OrElse _
10:     (FD.DescriptionRow Is Nothing OrElse FD.DescriptionRow.ColumnMetadata Is Nothing) Then
11:         Exit Sub
12:     End If
13: 
14:     Dim CM As DbColumnInfo = FD.DescriptionRow.ColumnMetadata
15:     Dim MaxSize As Integer = CM.MaxLength
16:     If e.FormattedValue.ToString.Length > MaxSize Then
17:         Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = ColorConstants.MissingData
18:         Me.InvalidateCell(e.ColumnIndex, e.RowIndex)
19:         ShowMsg(String.Format("This field is limited to {0} characters.", MaxSize), _
20:             MsgBoxIcon.Critical, "Text is too long!")
21:         e.Cancel = True
22:     End If
23: End Sub

The class FieldDescriptor is filled in an earlier phase; its ColumnMetadata property holds a class with the column's metadata such as the varchar size. ShowMsg is a standard interface for providing feedback to the user in various application setups.

The problems I'm having are in trying to set the cell's style property. The change in the background color made in line 17 is never visible, even though I am calling InvalidateCell in the very next line. None of the other invalidate routines work, either. Worse, setting the cell's Style.BackGround property sets CellTemplate.Style.BackColor for the entire column, making my efforts to reset the cell's background to the default color in lines 5-7 pointless. WTF | :WTF:

Ok, fine, use the ErrorText property. Problem is, if I use e.Cancel = True then the error icon is never rendered, leaving the user with no feedback as to which cell has the error. If I do not set the Cancel property, then error icon is rendered; however, the validation is considered good and the database update (along with the truncation of data) proceeds.

Any suggestions on how to proceed?
QuestionWindows Workflow and dynamic workflows Pin
Mel Padden8-Sep-08 8:56
Mel Padden8-Sep-08 8:56 
AnswerRe: Windows Workflow and dynamic workflows Pin
Kevin McFarlane9-Sep-08 12:01
Kevin McFarlane9-Sep-08 12:01 
QuestionVOIP project Pin
AnoopSingh8-Sep-08 4:25
AnoopSingh8-Sep-08 4:25 
AnswerRe: VOIP project Pin
led mike8-Sep-08 4:56
led mike8-Sep-08 4:56 
QuestionRegular Expression for an email address in AD Pin
Vipul Mehta8-Sep-08 4:05
Vipul Mehta8-Sep-08 4:05 
AnswerRe: Regular Expression for an email address in AD Pin
Manas Bhardwaj8-Sep-08 4:12
professionalManas Bhardwaj8-Sep-08 4:12 
QuestionDetecting Hardwware changes for Non Plug and Play devices (Serial port). Pin
vinay_K8-Sep-08 0:31
vinay_K8-Sep-08 0:31 
QuestionSync Framework Released - v1 Pin
Howard Richards8-Sep-08 0:12
Howard Richards8-Sep-08 0:12 
AnswerRe: Sync Framework Released - v1 Pin
Kevin McFarlane9-Sep-08 8:39
Kevin McFarlane9-Sep-08 8:39 
Questionexcel spooling? Pin
balaji.t7-Sep-08 19:09
balaji.t7-Sep-08 19:09 
QuestionUpdate Properties In Running Threads Pin
cmancl7-Sep-08 17:27
cmancl7-Sep-08 17:27 
AnswerRe: Update Properties In Running Threads Pin
led mike8-Sep-08 5:07
led mike8-Sep-08 5:07 
Questionhow to have an image button column in my datagridview ? Pin
devboycpp7-Sep-08 12:07
devboycpp7-Sep-08 12:07 
AnswerRe: how to have an image button column in my datagridview ? Pin
John_Adams9-Sep-08 3:07
John_Adams9-Sep-08 3:07 
AnswerRe: how to have an image button column in my datagridview ? Pin
akhi4akhil16-Sep-08 2:41
akhi4akhil16-Sep-08 2:41 
QuestionNeed Suggestions for .NET Reporting Frameworks Pin
JPWheeler7-Sep-08 11:41
JPWheeler7-Sep-08 11:41 
AnswerRe: Need Suggestions for .NET Reporting Frameworks Pin
N a v a n e e t h7-Sep-08 18:52
N a v a n e e t h7-Sep-08 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.