By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,198 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,198 IT Pros & Developers. It's quick & easy.

program shut down when looping datagrid..

P: n/a
Hi
I have a datagrid that have checkboxes added to it and there is also a
button that I want to use as a check what rows has been selected in
the datagrid. But when I use this piece if code the program just
close when I press the button that is supposed to show the selected
rows in the datagrid

<code>

Public Function GetSelectedRows(ByVal dg As DataGrid) As
System.Collections.ArrayList

Dim al As New ArrayList
Dim cm As CurrencyManager = Me.BindingContext(dg.DataSource,
dg.DataMember)
Dim dv As DataView = CType(cm.List, DataView)
Dim i As Integer
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(i)
End If
End
Next
Return al
End Function 'GetSelectedRows

Private Sub btnMakePDF_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnMakePDF.Click
Dim s As String = "Selected rows:"
Dim o As Object
For Each o In GetSelectedRows(MyDataGrid)
s += " " + o.ToString()
Next o
MessageBox.Show(s)
'MessageBox.Show("Selected items....")
End Sub 'button1_Click

</code>
Does anyone know why?
Regards
Magnus
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> schrieb
I have a datagrid that have checkboxes added to it and there is also
a button that I want to use as a check what rows has been selected
in the datagrid. But when I use this piece if code the program
just close when I press the button that is supposed to show the
selected rows in the datagrid

<code>

Public Function GetSelectedRows(ByVal dg As DataGrid) As
System.Collections.ArrayList

Dim al As New ArrayList
Dim cm As CurrencyManager =
Me.BindingContext(dg.DataSource,
dg.DataMember)
Dim dv As DataView = CType(cm.List, DataView)
Dim i As Integer
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(i)
End If
End
Next
Return al
End Function 'GetSelectedRows


Maybe I misunderstood, but executing "End" is not there to keep the
application alive...
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
Your Command "End" should be "End Function" or so...

/Lars

"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> skrev i meddelandet
news:40********@Usenet.com...
Hi
I have a datagrid that have checkboxes added to it and there is also a
button that I want to use as a check what rows has been selected in
the datagrid. But when I use this piece if code the program just
close when I press the button that is supposed to show the selected
rows in the datagrid

<code>

Public Function GetSelectedRows(ByVal dg As DataGrid) As
System.Collections.ArrayList

Dim al As New ArrayList
Dim cm As CurrencyManager = Me.BindingContext(dg.DataSource,
dg.DataMember)
Dim dv As DataView = CType(cm.List, DataView)
Dim i As Integer
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(i)
End If
End
Next
Return al
End Function 'GetSelectedRows

Private Sub btnMakePDF_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnMakePDF.Click
Dim s As String = "Selected rows:"
Dim o As Object
For Each o In GetSelectedRows(MyDataGrid)
s += " " + o.ToString()
Next o
MessageBox.Show(s)
'MessageBox.Show("Selected items....")
End Sub 'button1_Click

</code>
Does anyone know why?
Regards
Magnus
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #3

P: n/a
* ma****@rad-o-resultat-dot-se.no-spam.invalid (magmo) scripsit:
I have a datagrid that have checkboxes added to it and there is also a
button that I want to use as a check what rows has been selected in
the datagrid. But when I use this piece if code the program just
close when I press the button that is supposed to show the selected
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(i)
End If
End

^^^

This will exit the app.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

P: n/a
Ahh, ok that explain a lot.

When I run the check, the check doesnt indicate that any rows are
selected even though I have selected rows in the datagrid. Does
anyone see what might be wrong?

Regards
Magnus
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #5

P: n/a
Hi,

Your code looks to see if the whole row is selected. Shouldn't you be
checking to see if the checkbox is checked?

Ken
-----------------

"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> wrote in message
news:40**********@Usenet.com:
Ahh, ok that explain a lot.

When I run the check, the check doesnt indicate that any rows are
selected even though I have selected rows in the datagrid. Does
anyone see what might be wrong?

Regards
Magnus
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
HYPERLINK "http://www.usenet.com"http://www.usenet.com


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.1.2 - Release Date: 6/7/2004
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.