-
Nov 26th, 2011, 10:09 AM
#1
Thread Starter
Addicted Member
DGV Selected Cells Problem
I created this code to work if I select Cell in DataGridView. The problem That I faced is when I select the Row it work too(because it sonsider the cells as selected).
How can I make it doesn't work for Row only for Cells as individual ?
vb Code:
For i As Integer = 0 To Me.DataGridView1.CurrentRow.Cells.Count - 1
If Me.DataGridView1.CurrentRow.Cells(i).Selected = True Then Exit Sub
Next
-
Nov 26th, 2011, 11:58 AM
#2
Re: DGV Selected Cells Problem
Originally Posted by mangore
I created this code to work if I select Cell in DataGridView. The problem That I faced is when I select the Row it work too(because it sonsider the cells as selected).
How can I make it doesn't work for Row only for Cells as individual ?
vb Code:
For i As Integer = 0 To Me.DataGridView1.CurrentRow.Cells.Count - 1
If Me.DataGridView1.CurrentRow.Cells(i).Selected = True Then Exit Sub
Next
If you select the entire row then SelectedCells will contain each cell.
If you had not selected the entire row but only one or more columns, less than the total columns you could use code such as the following to see which columns are selected for the current row that is not selected with the row selector (which would return all columns on the current row). The code assumes your DataGridView has allow new rows set to false.
Code:
If DataGridView1.SelectedCells IsNot Nothing Then
Dim Data1 = (From D In DataGridView1.SelectedCells.Cast(Of DataGridViewCell)() _
Where D.RowIndex = DataGridView1.CurrentRow.Index _
Select D Order By D.ColumnIndex).ToList
For i As Integer = 0 To Data1.Count - 1
Console.WriteLine(Data1(i).ColumnIndex)
Next
End If
-
Nov 26th, 2011, 05:13 PM
#3
Thread Starter
Addicted Member
Re: DGV Selected Cells Problem
I'm confusing about this code. Because I'm new in vb.net
-
Nov 26th, 2011, 06:00 PM
#4
Re: DGV Selected Cells Problem
Originally Posted by mangore
I'm confusing about this code. Because I'm new in vb.net
What I gave you is per-say advance but it should not stop you from trying it which once tried will show results in the IDE output window thus seeing what it did. From there you can ask questions rather than simply saying "I'm confused."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|