C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » DataGridView »

DataGridView Checkbox Column Handling in VB.NET


Posted Date: 30 Jun 2009    Resource Type: Code Snippets    Category: DataGridView
Author: Viji RAJKUMARMember Level: Diamond    
Rating: 1 out of 5Points: 10



Problem Description

We encounter a situation where we need to edit the Datagridview rows based on the value of Datagridview Checkbox column Cell.

But the datagridview Checkbox cell will not commit immediately after checking the cell.It will be committed only after checking the next cell.

So the below solution makes the cell to commits it's value once it is checked.

Solution Description

Bind the data to the Datagridview.Place the below code in the CurrentCellDirtyStateChanged event of the datagridview.

When the user checks the cell,CurrentCellDirtyStateChanged event wiil be fired and then cell's dirty stae is checked.

If so, CommitEdit method is called.


Sample Coding



Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged

Dim dgCheckBoxCell As DataGridViewCheckBoxCell

Try
'Checking whether the Datagridview Checkbox column is the first column
If DataGridView1.CurrentCellAddress.X = 0 Then
dgCheckBoxCell = DataGridView1.CurrentRow.Cells(0)

If (DataGridView1.IsCurrentCellDirty) Then 'Checking for dirty cell
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) 'If it is dirty, making them to commit

If (dgCheckBoxCell.Value) Then
'Enabling the selected row editable for sample.

DataGridView1.CurrentRow.Cells("EmpID").ReadOnly = False
DataGridView1.CurrentRow.Cells("Designtn").ReadOnly = False
DataGridView1.CurrentRow.Cells("Location").ReadOnly = False
DataGridView1.CurrentRow.Cells("Experience").ReadOnly = False

Else
'Disabling the selected row for editing.

DataGridView1.CurrentRow.Cells("EmpID").ReadOnly = True
DataGridView1.CurrentRow.Cells("Designtn").ReadOnly = True
DataGridView1.CurrentRow.Cells("Location").ReadOnly = True
DataGridView1.CurrentRow.Cells("Experience").ReadOnly = True

End If
End If
End If

Catch ex As Exception
End Try
End Sub




For more details, visit http://vijirajkumar.blogspot.com/2009/06/datagridview-checkbox-column-handling.html



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
DataGridView Checkbox Column Handling in VB.NET  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Auto Complete For a TextBox Control in DataGridView
Previous Resource: Custom Built -DataGridView with Select /Deselect all checkbox
Return to Discussion Resource Index
Post New Resource
Category: DataGridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use