datagridviewselectedcellcollection usage

I don't know how to correct my errors
1. oncellclick is not declared                 'oncellclick(returnvalue)
2. statement is not a valid namespace  'private sub oncellclick (Byval e as datagridviewcelleventargs) ...
3. statement is not a valid namespace  'private sub dgvvoc_cellmouseleave(Byval sender as object, ...
What I 'm try to do is to to select a cell from dgvvoc by calling oncellclick and load retrrnvalue to ds through talistbox.fill and then load ds to datagridveiw1.  No special purpose, just trying to learn coding.
Thank you, please help.
Imports System.Windows.Forms
Imports System.Data
Imports System.Reflection
 
Public Class Form2
   
    Dim tavocab As iniisisDataSetTableAdapters.vocabListTableAdapter
    Dim tausg As iniisisDataSetTableAdapters.gUsgListTableAdapter
    Dim tath As iniisisDataSetTableAdapters.thListTableAdapter
    Dim tati As iniisisDataSetTableAdapters.tIndexListTableAdapter
    Public Sub New()
 
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        Dim conn As OleDb.OleDbConnection
        conn = New OleDb.OleDbConnection()
        conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source='c:documents and settings\isischen\documents\iniisis.mdb'"
        ' Add any initialization after the InitializeComponent() call.
        tath = New iniisisDataSetTableAdapters.thListTableAdapter
        tausg = New iniisisDataSetTableAdapters.gUsgListTableAdapter
        tati = New iniisisDataSetTableAdapters.tIndexListTableAdapter
        tavocab = New iniisisDataSetTableAdapters.vocabListTableAdapter
    End Sub
    Private Sub TIndexListBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TIndexListBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TIndexListBindingSource3.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.IniisisDataSet)
 
    End Sub
 
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'IniisisDataSet.gUsgList' table. You can move, or remove it, as needed.
 
        Me.GUsgListTableAdapter.Fill(Me.IniisisDataSet.gUsgList)
        'TODO: This line of code loads data into the 'IniisisDataSet.vocabList' table. You can move, or remove it, as needed.
        Me.VocabListTableAdapter.Fill(Me.IniisisDataSet.vocabList)
        'TODO: This line of code loads data into the 'IniisisDataSet.thList' table. You can move, or remove it, as needed.
        Me.ThListTableAdapter.Fill(Me.IniisisDataSet.thList)
        'TODO: This line of code loads data into the 'IniisisDataSet.tIndexList' table. You can move, or remove it, as needed.
        Me.TIndexListTableAdapter.Fill(Me.IniisisDataSet.tIndexList)
 
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim dvVocab As DataView
        Dim returnvalue As DataGridViewSelectedCellCollection
        dvVocab.Table = IniisisDataSet.Tables("vocabList")
        dvVocab.RowFilter = "vocab = abandon"
        dgvvoc.DataSource = dvVocab
        returnvalue = dgvvoc.SelectedCells
        oncellclick(returnvalue)
 
    End Sub      
End Class
 
Private Sub oncellclick(ByVal e As DataGridViewCellEventArgs) Handles dgvvoc.CellMouseEnter
 
    Dim returnvalue As String
    Dim dgvinstance As DataGridViewSelectedcellcollection
    Dim talistbox As New System.Data.Common.DataAdapter
    Dim e As datagridviewcelleventargs
 
    dgvinstance = New DataGridView()
    returnvalue = e.Tostring()
    talistbox.fill(ds, returnvalue)
    datagridview1.datasuouce = ds
End Sub
Private Sub dgvvoc_CellMouseLeave(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dgvvoc.CellMouseLeave
 
    dataGridView1.Cursor = Cursors.Default
End Sub

Open in new window

isischenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Smart_ManCommented:
what are the compiling errors ?
0
SanclerCommented:
Let's start with line 57

Private Sub oncellclick(ByVal e As DataGridViewCellEventArgs) Handles dgvvoc.CellMouseEnter

First of all, the DataGridView already has a method called OnCellClick.  It is declared as Overridable, so - if you want to change what it does - you can.  But I am not sure that is really what you are seeking to do.  Rather, although it's difficult to be sure of the objectives just by reading the code, it looks to me as though you want to create a method which has nothing to do with clicking a cell.

Second, you are declaring that sub as a "delegate": that's what the "Handles ..." bit at the end means.  Now, when you create a method to handle an event - that is, a "delegate" - it has to have the same "signature" - that is, the same arguments in the same order - as the inbuilt EventHandler.  The signature of the DataGridView.CellMouseEnterEventHandler is

Public Delegate Sub DataGridViewCellEventHandler (sender As Object, e As DataGridViewCellEventArgs)

That is, besides "ByVal e As DataGridViewCellEventArgs", it includes, as its first argument, "sender As Object".  So line 57 will not be valid.  Its signature is different from that needed to handle dgvvoc.CellMouseEnter.

Now although that explanation does not precisely explain the exact form of some of the error messages you are reporting, I think it does - for instance - explain "oncellclick is not declared".  That is because an INVALID declaration is treated as no declaration at all.

I've gone into some - perhaps confusing - technical detail on a single point.  I think there are lots of others but, as I say, I find it difficult to discern from your code as it stands exactly what your aims are.  

But what I think you really need to do is make more use of the inbuilt aids to coding which VB.NET provides.  So, for instance, if you want some code to occur on a DataGridView's CellMouseEnter, you can select the DataGridView in the lefthand dropdown at the top of the code window and then select CellMouseEnter in the righthand dropdown and the proper signature for the necessary method will appear in the code window: you just fill it in.  And, when you are coding, if a blue wavy line appears under anything you have typed, it means there is something wrong.  You can find out what is wrong by hovering the mouse over the bit concerned or looking in the ErrorList: and you may even - depending on your settings - be able to see a pop-up containing suggestions for putting it right.

Roger
0
Smart_ManCommented:
waiting for your reply
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

isischenAuthor Commented:
I wasn't able to start debug due to three errors:
1. oncellclick is not declared                 'oncellclick(returnvalue)
2. statement is not a valid namespace  'private sub oncellclick (Byval e as datagridviewcelleventargs) ...
3. statement is not a valid namespace  'private sub dgvvoc_cellmouseleave(Byval sender as object, ...

Roger, I will try to correct your suggestion on error 1 and error 2. Thanks

Smart Man, do I need line 69?
0
isischenAuthor Commented:
Roger, there's a blue line underneath the word delegate and show "key word  is not valid as identifier".
Also the error on line 52 is still the same after I tried
Public delegate Sub DataGridViewCellEventHandler (sender As Object, e As DataGridViewCellEventArgs)

I change the line 66 to
  talistbox.Fill(ds, e.Tostring())
show " overload resolution failed becauce no accessible Fill accept this number of arguments"
0
Smart_ManCommented:
i do not see you using the CellMouseLeave anywhere else

waiting for your reply
0
SanclerCommented:
I'm sorry.  I seem to have confounded your confusion with my quotation of

Public Delegate Sub DataGridViewCellEventHandler (sender As Object, e As DataGridViewCellEventArgs)

I included that as part of the explanation of why the specified bit - line 57 - of your current code was not working.  I did not intend you to copy it into your code.  My point was that if you wished to have a sub that "Handles dgvvoc.CellMouseEnter" then it needed to have "(sender As Object, e As DataGridViewCellEventArgs)" as its arguments.

I could just have said

>>
Change line 57 to

Private Sub oncellclick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvvoc.CellMouseEnter
<<

but I saw little point in doing that without a much better understanding of what your code is trying to do.  As it stands at the moment - and I said previously that my comments were only dealing with one example - I'm afraid it does not make a lot of sense.  Nor can I make much sense of your description "What I 'm try to do is to to select a cell from dgvvoc by calling oncellclick and load retrrnvalue to ds through talistbox.fill and then load ds to datagridveiw1."

Forget the code for a while.  Please describe in narrative terms what you want to happen.  Is it supposed to happen when the mouse enters a cell in dgvvoc or only when Button3 is clicked or what?  What is the relationship between what is selected in dgvvoc and what you want to go into datagridview1?  The reason for the blue wavy line on "talistbox.Fill(ds, e.Tostring())" is that the second argument is supposed to be the name of a datatable and - although it's difficult to be certain what it is - "e.ToString()" is unlikely to be that.  But that's not, at the moment, really relevant.  The code you show is not going to work for all sorts of other reasons.  Until we understand what its overall purpose is supposed to be, it is a waste of time and effort (and - see above - probably just confusing) to make specific suggestions about changing this to that.

Roger
0
isischenAuthor Commented:
When botton3 gets clicked line 47 and 51 is suppose to load dgvvoc's selected cells into returnvalue which gets pass to sub oncellclick's e where I want to use e as datasource for datagridview1.
I have cellmouseleave event delgated in line 69-74 and I don't know how to use it.
0
isischenAuthor Commented:
I change line 57-68 to
Public Sub oncellclick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvvoc.CellMouseEnter

        'Dim dgvinstance As DataGridViewSelectedCellCollection
        Dim ds As New DataSet()
        DataGridView1.DataSource = e.ToString()
    End Sub
After this I have only one error shown as:
arguement not specified for parmeter 'e' of public sub oncellclick
I guess back in line 52 I did not do it right when I call public sub oncellclick, right?  
What can I do about the above error message?
0
SanclerCommented:
The simple answer is that you cannot "use e as datasource for datagridview1."  e - in the context you are talking about here - is an instance of DataGridViewCellEventArgs.  It does not contain any "data".  It has two properties - .RowIndex and .ColumnIndex - which refer to a cell in the DataGridView which (in normal circumstances) raised the Event to which the code which receives the DataGridViewCellEventArgs is reacting and would be the "sender" in the arguments of the call to which the code is reacting.

A DataSource contains "data".  An appropriate example from your code would be on line 50.  There, the .DataSource is the DataView dvVocab which "contains" filtered rows from the DataTable IniisisDataSet.Tables("vocabList").

But your answers are missing my point.  You are still talking in terms of detailed coding.  Coding is a means to an end.  What we need to know is what that "end" is.  The "means" you are trying to use are wrong - in all sorts of respects.  You just repeating (and playing with details of) the "means" gets us no nearer to knowing what you are trying to achieve.  And until we know that we can't help you.

You appear to envisage two DataGridViews - dgvvoc and datagridview1.  You appear to envisage the user selecting some cells in dgvvoc and then clicking on Button3.  Now the question is: WHAT data are you wanting to appear in datagridview1 as a result of that click on Button3?  It must be assumed that - because you have envisaged that it has been preceded by the user selecting some cells in dgvvoc - that the data to be shown in datagridview1 would be different depending on precisely which cells had been selected in dgvvoc.  But HOW would what had been selected in dgvvoc affect what you wanted to appear in datagridview1?  And, remembering that the DataSource for a DataGridView has to contain "data" - it has to be be, for example, a DataView or a DataTable or some sort of "List" - WHERE is the data that datagridview1 actually held?

Roger
0
isischenAuthor Commented:
- But HOW would what had been selected in dgvvoc affect what you wanted to appear in datagridview1?
I don't know the answer to this question.  I was hoping these two line will take care of it.
        returnvalue = dgvvoc.SelectedCells
        oncellclick(returnvalue)
- The simple answer is that you cannot "use e as datasource for datagridview1
Here I thought when I declare e as DataGridViewCellEventArgs e is going to be the event arguement for the mouseenter event..I was'nt sure about that.
Since I cannot use e as datasource there's no point for trying to make my module work-- to just load datasoure to datagrid and from reload partial data to another datagrid?
0
SanclerCommented:
You don't seem to have appreciated the distinction I have been trying to draw between "ends" and "means".

It now seems - although this is the first time you have actually said it - that what you are trying to do is "just load datasoure to datagrid and from reload partial data to another datagrid".  THAT is the "end" you are trying to acheve.  THAT is something that you might be able to achieve, although you will need to define the objective much more precisely that that before it could be properly coded.

When I said

>>
The simple answer is that you cannot "use e as datasource for datagridview1."
<<

all I meant was that you cannot "use e as datasource for datagridview1" as the "means" to achieve that end.

I include below code to illustrate how (a version of) your objective could be achieved.  Open a new project.  On the default form - Form1 - that that produces put two datagridviews - called dgvSource and dgvTarget - and one Button.  In dgvSource, using the designer, set SelectionMode to CellSelect.  Paste the code below into the code window.  Run it.  Select some cells in dgvSource and click the button.

Although the demo works with dummy data, the maketable sub is really the equivalent of filling tables with dataadapters or table adapters.  So - if this illustrates the sort of thing you are trying to achieve - it's the code in the Button1_Click sub that you need to study.

And, finally, let me stress that the code is just to illustrate one approach.  It's far from perfect (for instance, it can produce strange results if cells in dgvSource are individually selected in an "odd" order).  And there are other approaches.  But, as much as anything else, I've included it to reinforce my point that what you need to tell us is what it is you are trying to achieve.  Once we know that, we may be able to help.  But until we do, we can't.

Roger
Public Class Form1
 
    Private dtSource As New DataTable("Source")
 
    Private Sub maketable()
        Dim dc0 As New DataColumn("ID", GetType(Integer))
        dc0.AutoIncrement = True
        dtSource.Columns.Add(dc0)
        Dim dc1 As New DataColumn("Item1", GetType(String))
        dtSource.Columns.Add(dc1)
        Dim dc2 As New DataColumn("Item2", GetType(String))
        dtSource.Columns.Add(dc2)
        Dim dc3 As New DataColumn("Number1", GetType(Integer))
        dtSource.Columns.Add(dc3)
        Dim dc4 As New DataColumn("Number2", GetType(Integer))
        dtSource.Columns.Add(dc4)
        For i As Integer = 0 To 5
            Dim dr As DataRow = dtSource.NewRow
            dr("Item1") = "Item1" & i.ToString
            dr("Item2") = "Item2" & i.ToString
            dr("Number1") = i
            dr("Number2") = i * 10
            dtSource.Rows.Add(dr)
        Next
        dtSource.AcceptChanges()
    End Sub
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        maketable()
        dgvSource.DataSource = dtSource
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim dtTarget As New DataTable("Target")
        Dim lastRow As Integer = -1
        Dim dr As DataRow
 
        'make the target table
        For i As Integer = dgvSource.SelectedCells.Count - 1 To 0 Step -1
            Dim dgvc As DataGridViewCell = dgvSource.SelectedCells(i)
            'get the column name
            Dim colname As String = dgvc.OwningColumn.Name
            'is it already in the table?
            If Not dtTarget.Columns.Contains(colname) Then
                'NO
                'so add it, with the same name ...
                Dim coltype As System.Type = dgvc.OwningColumn.ValueType
                '... and datatype
                Dim dc As New DataColumn(colname, coltype)
                dtTarget.Columns.Add(dc)
            End If
        Next
 
        'fill the table
        For i As Integer = dgvSource.SelectedCells.Count - 1 To 0 Step -1
            Dim dgvc As DataGridViewCell = dgvSource.SelectedCells(i)
            'get the row index
            Dim thisrow As Integer = dgvc.RowIndex
            'is it one we're alrady working on?
            If thisrow <> lastRow Then
                'NO
                'so save it, if there is one we're working on
                If Not dr Is Nothing Then
                    dtTarget.Rows.Add(dr)
                End If
                'create a new row
                dr = dtTarget.NewRow
                'set the indicator of which row we're working on
                lastRow = thisrow
            End If
            'get the columnname
            Dim colname As String = dgvc.OwningColumn.Name
            'put the value in that column in that row
            dr(colname) = dgvc.Value
        Next
        'save the last row we were working on
        If Not dr Is Nothing Then
            dtTarget.Rows.Add(dr)
        End If
        dgvTarget.DataSource = dtTarget
    End Sub
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isischenAuthor Commented:
I do appreciate your trying to explain the difference between ends and means and everything else!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.