CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: help

  1. #1
    Join Date
    May 2002
    Posts
    6

    help

    Hi,
    I have a datagrid control having 3 columns.
    Also in my form I have 3 separate textboxes.
    And OnClick of a button I want the values from
    a selected record(or row) from the datagrid to
    be displayed in the 3 textboxes(ie each column
    value in a textbox)
    Can this be done?

  2. #2
    Join Date
    Oct 2001
    Posts
    36
    Yes....
    That's the simple answer. One way to do it...

    int selectedRow = dataGridOfStuff.CurrentRowIndex;
    DataGridCell currCell = new DataGridCell();
    // look at the different column values in the row
    currCell.RowNumber = currRow;
    currCell.ColumnNumber = 0;
    string value0 = dataGridEmployees[currCell].ToString().Trim() ;
    currCell.ColumnNumber = 1;
    string value1 = dataGridEmployees[currCell].ToString().Trim() ;
    currCell.ColumnNumber = 2;
    string value2 = dataGridEmployees[currCell].ToString().Trim() ;


    That will get you the values at least. There is probably a better way, but it will get you started playing around with it. And don't forget your try/catch blocks. You could also put this in the double-click event for the datagrid. That way you can still resize and sort the columns.

    Hope it helps.

  3. #3
    Join Date
    Oct 2001
    Posts
    36
    The line

    currCell.RowNumber = currRow;

    should have read

    currCell.RowNumber = selectedRow;

    sorry

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured