473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataGrid Multi Selections

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
Nov 21 '05 #1
7 1534
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

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

"Kenneth H. Young" <yo***@ncst.nrl.navy.mil> wrote in message
news:O3*************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #2
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

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Oa*************@TK2MSFTNGP10.phx.gbl...
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

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

"Kenneth H. Young" <yo***@ncst.nrl.navy.mil> wrote in message
news:O3*************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #3
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

"Kenneth H. Young" <yo***@ncst.nrl.navy.mil> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
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

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Oa*************@TK2MSFTNGP10.phx.gbl...
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

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

"Kenneth H. Young" <yo***@ncst.nrl.navy.mil> wrote in message
news:O3*************@TK2MSFTNGP12.phx.gbl...
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


Nov 21 '05 #4
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.

Nov 21 '05 #5
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
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:Wg**************@TK2MSFTNGXA02.phx.gbl...
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.

Nov 21 '05 #6
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.

Nov 21 '05 #7
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.

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
3
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source...
0
by: Ahmet AKGUN | last post by:
Hi; I have one application and one datagrid in it. I fill datagrid from one database on startup. Problem is that, I want to pass all data selected on datagrid to one DataTable class with all...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
2
by: Joanne | last post by:
Hi, I have an "interesting" problem with UserControls in a datagrid and I'm desperate for your help as I work alone and have no-one else to ask. It is quite complicated but I'll try to keep it...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
4
by: Noa | last post by:
Hi, Is there a way to use OpenFileDialog1 in order to multi-select folders? I saw in msdn site a sample of multi-file-selections. I need to select multiple folders and to apply an algorithm on...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
4
by: aaronkmar | last post by:
Hello Bytes, I hope this post finds you well on this wonderful Friday! I've been kicking this code around for over a week now and cannot seem to find the correct syntax to handle all of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.