Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am loading a DataGridView in VB.Net via either XML (if the file exists) or a datasource (if it doesn't). If a cell value is "N/A", I want to apply a cellstyle to that cell and make it readonly. I also have certain events that are being fired during user edit where the cell may get the N/A value. I'm able to more directly control setting the style and readonly there, but would like to do it in a manner where there are no potential "loop holes", where "N/A" has the default style and is editable.

I've explored many different cell events in the datagridview, but they don't fire when assigning the datasource. I've also tried using DataGridViewEditingControlShowingEvent, where I DirectCast a textbox textchanged event, but that seems to only occur on user edits as well.

Can someone help me come up with a way to assign a cellstyle and readonly property conditionally based on cell value upon assigning a datasource and the value in the cell = "N/A"?
Posted
Comments
S.Sls76 18-Nov-11 0:45am    
How can I Move cell from column 2 to column 5 direct on cellafteredit event?

1 solution

Try some thing like:
VB.NET
Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) _
Handles DataGridView1.CellBeginEdit
   If Not IsNumeric(DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value) Then
      e.Cancel = True
   End If
End Sub 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900