Allowing my method to "see" that a row has already been selected from my gridview.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Allowing my method to "see" that a row has already been selected from my gridview.

  1. #1
    Join Date
    May 2012
    Posts
    2

    Question Allowing my method to "see" that a row has already been selected from my gridview.

    Hello,

    My program has a gridview. It allows someone to select one of the rows.
    I store the selected row info using the following:

    GridViewRow row = GridView1.SelectedRow;

    Later on in the code, I was to call a method I wrote that needs to use "row" (i.e. the data stored in that row in the gridview).

    An exception is thrown saying that "Object reference not set to an instance of an object." I believe the method thinks that nothing has been selected....but it has been selected before this part of the code is called.

    How can I make my method "see" that the row has been selected and therefore go ahead and use "row" (the instance of GridViewRow that was instantiated earlier)

    Thank you,

  2. #2
    Join Date
    Oct 2011
    Posts
    97

    Re: Allowing my method to "see" that a row has already been selected from my gridview

    I don't really think you're giving us enough information. Why don't you post the code where you're getting the selected row, and post the code where you're using it. That might help us a bit.

    Also, please remember to use CODE tags when posting code.

  3. #3
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: Allowing my method to "see" that a row has already been selected from my gridview

    I would do it something like this
    Code:
    public string info;
    
    public void myMethod(string myInfo)
    {
              //do whatever you need to do with the information
    }
    
    private void GetInformation()
    {
           info = DataGrid.CurrentRow.Cells[whatever cell you need].Value.ToString();
           myMethod(info);
    }
    Last edited by forgottenhart; May 8th, 2012 at 10:32 PM. Reason: forgot to close the code tag

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center