|
-
Oct 7th, 2008, 12:17 PM
#1
Thread Starter
Banned
[RESOLVED] [2005] Label didn't count when selected dgv rows
Hi guys
I would like to know how I can make a single click and if i select more than one row, label should be counting the value how many rows i have selected.
Here it the code:
Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If Me.DataGridView1.SelectedCells.Count >= 1 Then
Label19.Text = DataGridView1.SelectedRows.Count
End If
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
DataGridView1.ClearSelection()
If DataGridView1.SelectedCells.Count <= 0 Then
Label19.Text = "0"
End If
End Sub
When I select the row and when I select more than one row, label didn't counting the rows i have selected. Please let me know how i can resolve it??
Thanks,
Mark
-
Oct 7th, 2008, 12:44 PM
#2
Re: [2005] Label didn't count when selected dgv rows
What is your DGV's SelectionMode property set to?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 7th, 2008, 02:14 PM
#3
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
My DGV SelectionMode property are set to FullRowSelect. Any idea how the label can start to count when I click more than one row??
Thanks,
Mark
-
Oct 7th, 2008, 03:02 PM
#4
Re: [2005] Label didn't count when selected dgv rows
Hi,
Here's the code to count rows in a datagridview;
vb Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If Me.DataGridView1.SelectedCells.Count >= 1 Then Label19.Text = DataGridView1.SelectedRows.Count +1 End If End Sub
Wkr,
sparrow1
-
Oct 7th, 2008, 03:10 PM
#5
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
Hi
Thanks for your reply, i have paste the code on my form and I have debug the project to see if there is a change but unfortunately, when I click the cell with a single click and I select more than one cell like 10 cells, label did not count up.
Any idea how to get this situation resolve??
Thanks,
Mark
 Originally Posted by sparrow1
Hi,
Here's the code to count rows in a datagridview;
vb Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If Me.DataGridView1.SelectedCells.Count >= 1 Then
Label19.Text = DataGridView1.SelectedRows.Count +1
End If
End Sub
Wkr,
sparrow1
-
Oct 7th, 2008, 03:20 PM
#6
Re: [2005] Label didn't count when selected dgv rows
Hi,
The code I've gave you, works for me!
What does the label gives you when you debug and click a row?
The label in my test app gives me directly 2
Wkr,
sparrow1
-
Oct 7th, 2008, 03:25 PM
#7
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
It didn't work for me when I click the cell and select more than one cell.
The label stays 1 when i click the cell and select more than one.
Any idea how to fix??
Thanks,
Mark
-
Oct 7th, 2008, 03:31 PM
#8
Fanatic Member
Re: [2005] Label didn't count when selected dgv rows
Are you clicking a cell in the same row as one of the other ones? If you do not have fullrowselect on and it only gives you a single cell then that is the problem. the SelectedRows Property will only count the rows that have selected items in the datagridview.
If you are counting individual cells try (without fullrowselect on):
Code:
DataGridView1.SelectedCells.Count.ToString
You will know if you have fullrowselect on by clicking on a cell, if the entire row highlights then you have fullrowselect on.
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
Oct 7th, 2008, 03:36 PM
#9
Re: [2005] Label didn't count when selected dgv rows
Hi,
What you can try is:
Make a new private sub Datagridview1_CellClick and try again.
Your very sure that the selectionmode is set to FullRowSelectand you didn't change anything else.
Wkr,
sparrow1
-
Oct 7th, 2008, 03:44 PM
#10
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
Thanks for your reply dminder, do i have to input the code the one you post, do i have to put on cell click event??
Thanks,
Mark
 Originally Posted by dminder
Are you clicking a cell in the same row as one of the other ones? If you do not have fullrowselect on and it only gives you a single cell then that is the problem. the SelectedRows Property will only count the rows that have selected items in the datagridview.
If you are counting individual cells try (without fullrowselect on):
Code:
DataGridView1.SelectedCells.Count.ToString
You will know if you have fullrowselect on by clicking on a cell, if the entire row highlights then you have fullrowselect on.
D
-
Oct 7th, 2008, 03:47 PM
#11
Re: [2005] Label didn't count when selected dgv rows
 Originally Posted by Mark107
My DGV SelectionMode property are set to FullRowSelect. Any idea how the label can start to count when I click more than one row??
Thanks,
Mark
If that is the case then all you need to do is to get the count of the SelectedRows. There's no need to count the selectedcells.
Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Label19.Text = DataGridView1.SelectedRows.Count.ToString()
Label19.Refresh()
End Sub
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 7th, 2008, 04:21 PM
#12
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
Thanks for your reply, but it is still the same where it was when I click the cell and select more than one row that the label are still showing 1 cell that have been selected. I have selected more than 10 cells but it didn't show up any update.
I don't know how we can situation this and get it into resolve. Any idea??
Thanks,
Mark
-
Oct 8th, 2008, 07:11 AM
#13
Fanatic Member
-
Oct 8th, 2008, 09:28 AM
#14
Re: [2005] Label didn't count when selected dgv rows
 Originally Posted by Mark107
Thanks for your reply, but it is still the same where it was when I click the cell and select more than one row that the label are still showing 1 cell that have been selected. I have selected more than 10 cells but it didn't show up any update.
I don't know how we can situation this and get it into resolve. Any idea??
Thanks,
Mark
Are you counting the selected cells or are you counting the selected rows of the DGV? In the 1st post you wrote: "if i select more than one row, label should be counting the value how many rows i have selected..." and now you are saying that you want to count the selected cells... The 2 things are totally different, and please make up your mind as to which way you want to go.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 9th, 2008, 01:18 PM
#15
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
I want to counting the selected rows of the DGV. I am sorry for posting the wrong situation. Hope this is the right one that you can assist me with this.
Thanks,
Mark
-
Oct 9th, 2008, 01:20 PM
#16
Fanatic Member
Re: [2005] Label didn't count when selected dgv rows
Well then Post #11 will answer your question.
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
Oct 9th, 2008, 02:47 PM
#17
Re: [2005] Label didn't count when selected dgv rows
Mark, probably we all misunderstand what you said you want. So let's back out a little bit and try to settle on our understanding of the problem. You have a DGV with SelectionMode set to FullRowSelect (that is, if you click on any cell on a row, that whole row is highlighted indicating that it's selected). Now suppose that you click on a cell in row#1, the label show 1 row selected and the is only one row highlighted in your DGV, right... So far so good. Now you click on a cell in row#2. Again, row#2 is highlighted and it still the only highlighted row in the DGV (because when you click on this row, the 1st row is automatically unselected)... So unless you hold down the shift key or control key while clicking on another row, and your DGV is allowed for multiselection, there is only 1 selected row at any given time, and that selected row is the row that you last clicked on. And that's the reason why your label always shows 1 row selected.
If you want that label to count up each time a row is selected then you have to say so, otherwise we all try to solve the wrong puzzle for nothing.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 11th, 2008, 01:29 PM
#18
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
I have tried it but it still unresolved.
Please help!!!!!!!!!!
 Originally Posted by dminder
Well then Post #11 will answer your question.
D
-
Oct 11th, 2008, 06:19 PM
#19
Re: [2005] Label didn't count when selected dgv rows
Hey,
Did you read stanav's post, #17.
Is this the situation that you desire? Can you specify exactly what you want to achieve?
Gary
-
Oct 12th, 2008, 04:05 PM
#20
Thread Starter
Banned
Re: [2005] Label didn't count when selected dgv rows
I am trying to achieve by selected selected one row of the DGV then select more rows while label is counting the rows i select.
Thanks,
Mark
-
Oct 12th, 2008, 04:22 PM
#21
Re: [2005] Label didn't count when selected dgv rows
So can you explain why the code that was posted in post #11 does not do what you want?
It would appear to me that it should.
Gary
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
|