DataGrid Multi Selections

  • Thread starter Thread starter Kenneth H. Young
  • Start date Start date
K

Kenneth H. Young

How does one get the values of multiple selected rows in a DataGrid? I
am trying to allow the builing of an email list generated from an LDAP
query. The below code works OK but it can create duplicates if a line item
is clicked more that once.

Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Click
Dim curCell, systemDirectory, mList, writeL As String

systemDirectory = System.Environment.SystemDirectory & "\"

mList = systemDirectory & "mailList.txt"

curCell = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3) '3 is the email
column.

DataGrid1.CurrentCell.Equals(curCell)

Dim writeE As System.IO.TextWriter

FileOpen(1, mList, OpenMode.Append)

WriteLine(1, curCell)

FileClose(1)

End Sub



Thanks for the help

Kenneth H. Young
 
Hi,

Here is how to tell which rows are selected.

For x As Integer = 0 To Me.BindingContext(DataGrid1.DataSource).Count - 1

Debug.WriteLine(String.Format("{0} {1}", x, DataGrid1.IsSelected(x)))

Next



Ken

--------------------------------

How does one get the values of multiple selected rows in a DataGrid? I
am trying to allow the builing of an email list generated from an LDAP
query. The below code works OK but it can create duplicates if a line item
is clicked more that once.

Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Click
Dim curCell, systemDirectory, mList, writeL As String

systemDirectory = System.Environment.SystemDirectory & "\"

mList = systemDirectory & "mailList.txt"

curCell = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3) '3 is the email
column.

DataGrid1.CurrentCell.Equals(curCell)

Dim writeE As System.IO.TextWriter

FileOpen(1, mList, OpenMode.Append)

WriteLine(1, curCell)

FileClose(1)

End Sub



Thanks for the help

Kenneth H. Young
 
Please excuse my ignorance but I don't understand how that determines
which row is selected and writes out the value of column 3 (the email
address).

I tried it and nothing is written to the file.

Once again thanks for the help

Private Sub bMail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bMail.Click

Dim systemDirectory, mList, readVal As String

systemDirectory = System.Environment.SystemDirectory & "\"

mList = systemDirectory & "mailList.txt"

FileOpen(1, mList, OpenMode.Output)

For x As Integer = 0 To Me.BindingContext(DataGrid1.DataSource).Count - 1

Debug.WriteLine(String.Format("{0} {1}", x, DataGrid1.IsSelected(x)))

Next

FileClose()

End Sub
 
I have tried the following and it only writes out the first selected
items email address.

Private Sub bMail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bMail.Click

Dim systemDirectory, mList, readVal, curCell As String

systemDirectory = System.Environment.SystemDirectory & "\"

mList = systemDirectory & "mailList.txt"

FileOpen(1, mList, OpenMode.Output)

For x As Integer = 0 To Me.BindingContext(DataGrid1.DataSource).Count - 1

Debug.WriteLine(String.Format("{0} {1}", x, DataGrid1.IsSelected(x)))

curCell = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3)

WriteLine(1, curCell)

Next

FileClose()

End Sub
 
Hi

I think you may to use the code below to get the selected rows.
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Click
Dim cm As CurrencyManager =
CType(BindingContext(DataGrid1.DataSource, DataGrid1.DataMember),
CurrencyManager)
Dim dv As DataView = CType(cm.List, DataView)
For x As Integer = 0 To dv.Count - 1
If (DataGrid1.IsSelected(x)) Then
Debug.WriteLine(String.Format("{0} is selected", x))
Dim drv As DataRowView = dv(x)
Debug.WriteLine(drv("CustomerID").ToString())
End If
Next
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Below is what I finally got to work so I can create an email list.
Thanks for all the help and pointing me in the right direction.

Private Sub bMail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bMail.Click
Dim systemDirectory, mList, readVal, curCell As String
Dim Exists As Boolean
systemDirectory = System.Environment.SystemDirectory & "\"
mList = systemDirectory & "mailList.txt"
Exists = System.IO.File.Exists(mList)
If Exists = True Then
System.IO.File.Delete(mList)
End If
FileOpen(1, mList, OpenMode.Append)
For x As Integer = 0 To DataSet11.Employees.Count - 1

If Me.DataGrid1.IsSelected(x) = True Then
curCell = DataGrid1.Item(x, 3)
WriteLine(1, curCell)

Else

End If
Next
FileClose()
End Sub
 
Hi

I am glad that you have the solution at last.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top