locked
call a method RRS feed

  • Question

  • Hello. I'm having trouble calling a method that holds one string called text. How do i call this method. Any help would be greatly appreciated. Here's the method.

        public void addInformation(string text)
    
    
    

    Here is where it needs to go

     credits.Person = this.dtgrdCredits.Columns["cboInformation"].DataGridView.Rows.ToString();


    PCRider

    • Moved by CoolDadTx Thursday, May 17, 2012 2:09 PM Winforms related (From:Visual C# General)
    Thursday, May 17, 2012 2:00 PM

Answers

  • Calling a method is as simple as:

    instance.addInformation("someString");

    I don't understand what part of the second block of code is related to calling the method.  The second block of code is taking a string and assigning it to a property of some object. 

    Note that Rows.ToString() isn't doing what you want.  Let's break that call down.

    this.dtgrdCredits gets a DGV control instance

    Columns[""] gets the column instance with the given name

    DataGridView gets the DGV associated with that column (which is dtgrdCredits)

    Rows gets the list of all rows in the DGV

    ToString gets the string representation of a rows collection which would just be the type

    If you want to get the value of a cell in the grid then use something like this:

    this.dtgrdCredits.Rows[someRowIndex].Cells[cboInformation].Value

    But this is generally not how you work with DGV. Generally you only work with the bound data source. Working with cells directly is an advanced topic. I'm moving this to the correct forum for further assistance. The C# General forum is not for UI technologies.

    Michael Taylor - 5/17/2012
    http://msmvps.com/blogs/p3net

    • Proposed as answer by Bob Wu-MT Friday, May 18, 2012 6:50 AM
    • Marked as answer by Bob Wu-MT Friday, June 8, 2012 6:37 AM
    Thursday, May 17, 2012 2:09 PM

All replies

  • credits.Person = this.dtgrdCredits.Columns["cboInformation"].DataGridView.Rows.ToString();

    Then:

    addInformation(credits.Person);


    John Grove, Senior Software Engineer http://www.digitizedschematic.com/

    Thursday, May 17, 2012 2:07 PM
  • Calling a method is as simple as:

    instance.addInformation("someString");

    I don't understand what part of the second block of code is related to calling the method.  The second block of code is taking a string and assigning it to a property of some object. 

    Note that Rows.ToString() isn't doing what you want.  Let's break that call down.

    this.dtgrdCredits gets a DGV control instance

    Columns[""] gets the column instance with the given name

    DataGridView gets the DGV associated with that column (which is dtgrdCredits)

    Rows gets the list of all rows in the DGV

    ToString gets the string representation of a rows collection which would just be the type

    If you want to get the value of a cell in the grid then use something like this:

    this.dtgrdCredits.Rows[someRowIndex].Cells[cboInformation].Value

    But this is generally not how you work with DGV. Generally you only work with the bound data source. Working with cells directly is an advanced topic. I'm moving this to the correct forum for further assistance. The C# General forum is not for UI technologies.

    Michael Taylor - 5/17/2012
    http://msmvps.com/blogs/p3net

    • Proposed as answer by Bob Wu-MT Friday, May 18, 2012 6:50 AM
    • Marked as answer by Bob Wu-MT Friday, June 8, 2012 6:37 AM
    Thursday, May 17, 2012 2:09 PM
  • Good catch CoolDadTx, missed that in my haste.

    John Grove, Senior Software Engineer http://www.digitizedschematic.com/

    Thursday, May 17, 2012 2:11 PM