Home Forums WinForms controls Xceed Grid for WinForms Add rows to Detail Grid

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13677 |

    I have been able to add rows to the master grid fine. Now need to add rows with a context menu to the detail grid. Is it possible to do this in code, without using the insertion row?

    Imported from legacy forums. Posted by KenG (had 8316 views)

    User (Old forums)
    Member
    Post count: 23064

    Xceed.Grid.DataRow row = myDetailGrid.DataRows.AddNew();
    row.EndEdit();

    Imported from legacy forums. Posted by Tommy (had 921 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy!

    Now the customer wants to right click on one of the records in teh detail grid and insert a new row with an incremented default value in the first cell. I need to filter through the records in teh detail grid to get the previous row’s value. Having a hard time figuring our how to do that as there isn’t a .Selected Rows option in the detail grid.

    Any thoughts would be welcomed…
    Thanks again!

    Imported from legacy forums. Posted by KenG (had 410 views)

    User (Old forums)
    Member
    Post count: 23064

    Can’t you just add an insertion row to the detail grid? That way, your customers don’t have to right-click. The InsertionRow-class has an event called <b>RowInserted</b>. If you catch that event, you can iterate through the DataRows of the DetailGrid to find the incremented new value for that inserted row.

    Imported from legacy forums. Posted by Tommy (had 422 views)

    User (Old forums)
    Member
    Post count: 23064

    What customer are basically looking for is the functionality to insert a row in the middle of a group of rows in the detail grid.

    Example:
    Detail grid has 4 rows. 1st Cell in each row is the number of that row in the grid. Customer wants to right click on row 2 and insert a new row. The new row then becomes row 2, and each row after it is renumbered accordingly.

    In the master grid, I have achieved this by using a hidden column for sorting. ReNumbering works fine, and it appears to the customer to be inserting a row in the middle of a group of rows. They just want to be able to do the same in the detail grid.

    Ideas?

    If there is no way to achieve this, I will have to suggest the insertion row.

    Thanks for you thoughts.

    Imported from legacy forums. Posted by KenG (had 554 views)

    User (Old forums)
    Member
    Post count: 23064

    If you can do it in the master grid, what’s different in the detail grid?

    Imported from legacy forums. Posted by Tommy (had 488 views)

    User (Old forums)
    Member
    Post count: 23064

    Can’t seem to be able to access the detail grid’s contents.

    In the master grid, I can check for selected rows, or run through all of the datarows:
    foreach (Xceed.Grid.DataRow row in MyGrid.SelectedRows)
    or
    foreach (Xceed.Grid.DataRow row in MyGrid.DataRows)
    Depending on which I choose, I can either return the value of the first cell in just the row selected, or all of the rows in the grid.

    When I try in the detail grid, I can only code for all of the rows.
    foreach (Xceed.Grid.DataRow row in MyDetailGrid.DataRows)
    Then, I have to check to see if the row is selected
    if (row.IsSelected)
    {
    MessageBox.Show(row.Cells[“cell1”].Value.ToString());
    }

    I never receive a value.

    As a test, I did a MessageBox.Show to return the detail grid’s dataRow Count. It returned 0 every time.

    Not sure if I have to call the selected row in the Parent Grid before iterating through the detail grid, and if so, how to code it.

    Imported from legacy forums. Posted by KenG (had 462 views)

    User (Old forums)
    Member
    Post count: 23064

    All who have taken an interest in this thread

    My problem was assuming that the same loop would work with both grids. I forgot that the detail grid is considered a part of the master grid (or so to say). Therefore, you have to access the master grid, and call the detail grid from it. Here is the process of getting into the rows of the detail grid:

    If you have selected a row in the detail grid, you can get teh value in a message box using the following method:

    // First remember that the selected row is part of the master grid’s selected row list
    foreach (Xceed.Grid.DataRows parentRow in MyMasterGrid.SelectedRows)
    {
    // now create a row to represent the detail grid’s row
    foreach (Xceed.Grid.DataRow row in parentRow.ParentGrid.DataRows)
    {
    // Now create a cell to represent the cell you want the data from
    Xceed.Grid.Cell cell = row.Cells[“MyFirstCell”];
    MessageBox.Show(cell.Value.ToString());
    }
    }

    This returns the value in the cell for every row in the child grid.

    Thanks Tommy for you help. You got me on the right track.

    Imported from legacy forums. Posted by KenG (had 510 views)

    User (Old forums)
    Member
    Post count: 23064

    Too all that may be reading this post.
    I have not yet been able to add a row to the detail grid. I am currently working with Xceed Support on the issue.

    As quickly as I have working code, I will post it so all can see.
    Ken

    Imported from legacy forums. Posted by KenG (had 503 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks to the good folks at Xceed support, I have some working code regarding this issue.

    Here is what I end up with.
    If you have selected a row in the master grid,
    foreach (Xceed.Grid.DataRow dataRow in masterGrid.SelectedRows)
    {
    Xceed.Grid.DataRow newRow = dataRow.DetailGrids[0].DataRows.AddNew();
    // be sure to assign any required data
    newRow.Cells[“name of the cell”].Value = value;
    newRow.EndEdit();
    }

    If the selected row is in the detail grid,
    foreach (Xceed.Grid.DataRow dataRow in masterGrid.SelectedRows)
    {
    Xceed.Grid.DataRow newRow = dataRow.ParentGrid.DataRows.AddNew();
    // be sure to assign any required data
    newRow.Cells[“name of the cell”].Value = value;
    newRow.EndEdit();
    }

    It is imperitave that any required data be entered into the appropiate cell values or the row will not be created. There may be no errors to tell you what is going on.

    I hope this helps out. Please let me know if you find other code examples that works better, of if this code does not get you going.

    Thanks

    KenG

    Imported from legacy forums. Posted by KenG (had 791 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Ken,

    could you give me a hint how to get/set a value in the current row of a detail grid? Detail grids don’t have the CurrentRow-Property, so I don’t know how to get in there.

    Wolfgang

    Imported from legacy forums. Posted by wolfgang (had 576 views)

    User (Old forums)
    Member
    Post count: 23064

    Sure thing.

    One way is to select the row you want to get/set data to in the detail grid.
    You would want to get to it my accessing the selected row of the master grid.

    //Create a variable to hold any required data before accessing the grid.
    string getValue = “”;

    // Access the selected row
    foreach (Xceed.Grid.DataRow parentRow in myMasterGrid.SelectedRows)
    {
    // Then, if you need the value to the selected row, you can set it get it.
    row.Cells[“name of desired column”].value = Value;

    // or if you want to get the value

    getValue = row.Cells[“name of desired column”].Value.ToString();
    }

    Another way to get or set values is to rifle through all of the rows, compareing them with a condition statement. Something like:

    // Access the master grid first.
    foreach (Xceed.Grid.DataRow parentRow in myMasterGrid.DataRows)
    {
    // If you have selected a row in the detail grid to look for, or set values on
    // Start a new loop to get to the selected row
    foreach (Xceed.Grid.DataRow childRow in parentRow.DetailGrids[0].DataRows)
    {
    if (childRow.IsSelected)
    {
    getValue = childRow.Cells[“name of desired column”].Value.ToString();

    // Or to set the value
    childRow.Cells[“name of desired column”].Value = value;
    }
    }
    }

    Imported from legacy forums. Posted by KenG (had 614 views)

    User (Old forums)
    Member
    Post count: 23064

    Hope that helps Wolfgang
    KenG

    Imported from legacy forums. Posted by KenG (had 516 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks a lot, Ken. Works fine.

    I chose your second method and added an if…when…statement to check with the .MyDataRow(Index).IsCurrent(True))-Property, when I’m at the current row of the detail grid. That works, but is a bit akward. Isn’t there an easier way to get that? If not, we should suggest to the XCeed development team to implement a simple detailGrid.CurrentRow-Property. Shouldn’t be very difficult, as they already implemented the IsCurrent-Property for detail grids.

    Thanks again for your efforts!
    Wolfgang

    Imported from legacy forums. Posted by wolfgang (had 9225 views)

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.