PC Review


Reply
Thread Tools Rate Thread

DataGridView Event

 
 
John Wright
Guest
Posts: n/a
 
      29th Jun 2009
I have a datagridview on my form that has two columns. Column 0 is a
checkbox, column 1 is a text field. When a user checks or unchecks the
checkbox, I need to get a count of all the checked items in the datagrid. I
tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
event to fire for the first click.

I am attaching the code to show what I am doing (I am just looping through
the table and counting all the items where cell(0) is true). What event
should I use to get the value. When I use cellclick is doesn't register the
checkbox as checked/unchecked so the count is off. Thanks.

Code:
Dim intPieceCount As Integer = 0

Dim i As Integer = dgEPNItems.Rows.Count - 1
For x As Integer = i To 0 Step -1
If x < 0 Then
Exit For
End If
Dim dr As DataGridViewRow
dr = dgEPNItems.Rows(x)
If dr.Cells(0).Value = True Then
intPieceCount += 1
End If
Next
txtQuantity.Text = CStr(intPieceCount)

John
 
Reply With Quote
 
 
 
 
John Wright
Guest
Posts: n/a
 
      30th Jun 2009
Never mind, I figured it out.

"John Wright" wrote:

> I have a datagridview on my form that has two columns. Column 0 is a
> checkbox, column 1 is a text field. When a user checks or unchecks the
> checkbox, I need to get a count of all the checked items in the datagrid. I
> tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
> event to fire for the first click.
>
> I am attaching the code to show what I am doing (I am just looping through
> the table and counting all the items where cell(0) is true). What event
> should I use to get the value. When I use cellclick is doesn't register the
> checkbox as checked/unchecked so the count is off. Thanks.
>
> Code:
> Dim intPieceCount As Integer = 0
>
> Dim i As Integer = dgEPNItems.Rows.Count - 1
> For x As Integer = i To 0 Step -1
> If x < 0 Then
> Exit For
> End If
> Dim dr As DataGridViewRow
> dr = dgEPNItems.Rows(x)
> If dr.Cells(0).Value = True Then
> intPieceCount += 1
> End If
> Next
> txtQuantity.Text = CStr(intPieceCount)
>
> John

 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      30th Jun 2009
Thanks for letting us know how you solved it.

On Tue, 30 Jun 2009 11:22:01 -0700, John Wright
<(E-Mail Removed)> wrote:

>Never mind, I figured it out.
>
>"John Wright" wrote:
>
>> I have a datagridview on my form that has two columns. Column 0 is a
>> checkbox, column 1 is a text field. When a user checks or unchecks the
>> checkbox, I need to get a count of all the checked items in the datagrid. I
>> tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
>> event to fire for the first click.
>>
>> I am attaching the code to show what I am doing (I am just looping through
>> the table and counting all the items where cell(0) is true). What event
>> should I use to get the value. When I use cellclick is doesn't register the
>> checkbox as checked/unchecked so the count is off. Thanks.
>>
>> Code:
>> Dim intPieceCount As Integer = 0
>>
>> Dim i As Integer = dgEPNItems.Rows.Count - 1
>> For x As Integer = i To 0 Step -1
>> If x < 0 Then
>> Exit For
>> End If
>> Dim dr As DataGridViewRow
>> dr = dgEPNItems.Rows(x)
>> If dr.Cells(0).Value = True Then
>> intPieceCount += 1
>> End If
>> Next
>> txtQuantity.Text = CStr(intPieceCount)
>>
>> John

 
Reply With Quote
 
John Wright
Guest
Posts: n/a
 
      30th Jun 2009
Well it appears no one else could, so I thought I would save someone the
trouble. Thank you sir, for responding.

"Jack Jackson" wrote:

> Thanks for letting us know how you solved it.
>
> On Tue, 30 Jun 2009 11:22:01 -0700, John Wright
> <(E-Mail Removed)> wrote:
>
> >Never mind, I figured it out.
> >
> >"John Wright" wrote:
> >
> >> I have a datagridview on my form that has two columns. Column 0 is a
> >> checkbox, column 1 is a text field. When a user checks or unchecks the
> >> checkbox, I need to get a count of all the checked items in the datagrid. I
> >> tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
> >> event to fire for the first click.
> >>
> >> I am attaching the code to show what I am doing (I am just looping through
> >> the table and counting all the items where cell(0) is true). What event
> >> should I use to get the value. When I use cellclick is doesn't register the
> >> checkbox as checked/unchecked so the count is off. Thanks.
> >>
> >> Code:
> >> Dim intPieceCount As Integer = 0
> >>
> >> Dim i As Integer = dgEPNItems.Rows.Count - 1
> >> For x As Integer = i To 0 Step -1
> >> If x < 0 Then
> >> Exit For
> >> End If
> >> Dim dr As DataGridViewRow
> >> dr = dgEPNItems.Rows(x)
> >> If dr.Cells(0).Value = True Then
> >> intPieceCount += 1
> >> End If
> >> Next
> >> txtQuantity.Text = CStr(intPieceCount)
> >>
> >> John

>

 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      30th Jun 2009
I was not thanking you for letting us know you solved it, but it was
an attempt at sarcasm, since you didn't tell us HOW you solved the
problem, and therefore your post won't help anyone else who has the
same problem.

On Tue, 30 Jun 2009 14:16:01 -0700, John Wright
<(E-Mail Removed)> wrote:

>Well it appears no one else could, so I thought I would save someone the
>trouble. Thank you sir, for responding.
>
>"Jack Jackson" wrote:
>
>> Thanks for letting us know how you solved it.
>>
>> On Tue, 30 Jun 2009 11:22:01 -0700, John Wright
>> <(E-Mail Removed)> wrote:
>>
>> >Never mind, I figured it out.
>> >
>> >"John Wright" wrote:
>> >
>> >> I have a datagridview on my form that has two columns. Column 0 is a
>> >> checkbox, column 1 is a text field. When a user checks or unchecks the
>> >> checkbox, I need to get a count of all the checked items in the datagrid. I
>> >> tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
>> >> event to fire for the first click.
>> >>
>> >> I am attaching the code to show what I am doing (I am just looping through
>> >> the table and counting all the items where cell(0) is true). What event
>> >> should I use to get the value. When I use cellclick is doesn't register the
>> >> checkbox as checked/unchecked so the count is off. Thanks.
>> >>
>> >> Code:
>> >> Dim intPieceCount As Integer = 0
>> >>
>> >> Dim i As Integer = dgEPNItems.Rows.Count - 1
>> >> For x As Integer = i To 0 Step -1
>> >> If x < 0 Then
>> >> Exit For
>> >> End If
>> >> Dim dr As DataGridViewRow
>> >> dr = dgEPNItems.Rows(x)
>> >> If dr.Cells(0).Value = True Then
>> >> intPieceCount += 1
>> >> End If
>> >> Next
>> >> txtQuantity.Text = CStr(intPieceCount)
>> >>
>> >> John

>>

 
Reply With Quote
 
Kevin S Gallagher
Guest
Posts: n/a
 
      8th Jul 2009
Since there was never a solution mentioned how about this for VS2008

<Runtime.CompilerServices.Extension()> _
Public Function CheckCount(ByVal GridView As DataGridView, ByVal ColumnIndex
As Integer, ByVal Checked As Boolean) As Integer
Dim Result = (From Rows In GridView.Rows.Cast(Of DataGridViewRow)() Where
CBool(Rows.Cells(ColumnIndex).Value) = Checked).ToList
If Not IsNothing(Result) Then
Return Result.Count
Else
'
' You decide how to handle
'
End If
End Function

' where column 0 is the column with the checkbox
Dim CheckedCount As Integer = DataGridView1.CheckCount(0, True)
MsgBox(CheckedCount)


"John Wright" <(E-Mail Removed)> wrote in message
news:058BF868-325B-4A20-92BA-(E-Mail Removed)...
>I have a datagridview on my form that has two columns. Column 0 is a
> checkbox, column 1 is a text field. When a user checks or unchecks the
> checkbox, I need to get a count of all the checked items in the datagrid.
> I
> tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
> event to fire for the first click.
>
> I am attaching the code to show what I am doing (I am just looping through
> the table and counting all the items where cell(0) is true). What event
> should I use to get the value. When I use cellclick is doesn't register
> the
> checkbox as checked/unchecked so the count is off. Thanks.
>
> Code:
> Dim intPieceCount As Integer = 0
>
> Dim i As Integer = dgEPNItems.Rows.Count - 1
> For x As Integer = i To 0 Step -1
> If x < 0 Then
> Exit For
> End If
> Dim dr As DataGridViewRow
> dr = dgEPNItems.Rows(x)
> If dr.Cells(0).Value = True Then
> intPieceCount += 1
> End If
> Next
> txtQuantity.Text = CStr(intPieceCount)
>
> John



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView and KeyDown event M K Microsoft C# .NET 3 3rd Jul 2007 10:41 PM
Does any one know which event is raised for a Datagridview after s =?Utf-8?B?UHVjY2E=?= Microsoft C# .NET 0 15th May 2007 03:28 AM
Updateing event of datagridview abhya Microsoft VB .NET 1 6th Mar 2007 09:50 AM
Key Down Event datagridview chris81 Microsoft VB .NET 0 2nd Nov 2006 10:16 AM
How to catch "new-row-editing-cancelled" event in DataGridView (isthere any similar event?) Paul Jones Microsoft Dot NET Framework Forms 2 25th Jul 2006 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 AM.