PC Review


Reply
Thread Tools Rate Thread

DataGrid Multi Selections

 
 
Kenneth H. Young
Guest
Posts: n/a
 
      17th Mar 2005
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


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      17th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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



 
Reply With Quote
 
Kenneth H. Young
Guest
Posts: n/a
 
      17th Mar 2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
Kenneth H. Young
Guest
Posts: n/a
 
      17th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:u%(E-Mail Removed)...
> 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]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> 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
>>
>>
>>

>
>



 
Reply With Quote
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      18th Mar 2005
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.

 
Reply With Quote
 
Kenneth H. Young
Guest
Posts: n/a
 
      18th Mar 2005
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-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      19th Mar 2005
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.

 
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
Re: tab order for multi-range selections Phil Microsoft Excel Misc 1 10th Aug 2009 04:01 AM
tab order for multi-range selections Phil Microsoft Excel Worksheet Functions 1 30th Jul 2009 05:57 PM
Saving selections in a multi-select list box =?Utf-8?B?UmViZWNjYU1pbkFS?= Microsoft Access Form Coding 7 18th Jul 2006 04:28 PM
Multi-select listbox losing selections zdrakec Microsoft ASP .NET 0 22nd Jul 2005 08:51 PM
Multi-view selections in one chart. joey31 Microsoft Excel Charting 1 24th Nov 2003 09:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:04 AM.