Programmatically Adding Grid Filters for Menu

Hello,

I’m customizing a menu where I have two UltraGrids and I’m trying to mimic the behaviour from Dashboard where if you click on the row of one grid, the rows of the second grid are filtered to match the first grid.

I’ve got some code started, not sure if I’m headed in a good direction. Any ideas?

            // Get the selected row from the left grid
            UltraGridRow selectedRow = epiHoursWorkedGrid.Selected.Rows[0];

            // Get the corresponding information to show in the right grid
            string employeeId = selectedRow.Cells["EmployeeIdColumnName"].Value.ToString(); // Change to the actual column name

            // Filter the right grid based on the selected employeeId
            DataTable rightGridTable = (DataTable)epiUltraGrid.DataSource;
            rightGridTable.DefaultView.RowFilter = $"EmployeeIdColumnName = '{employeeId}'"; // Change to the actual column name
            rightGridTable = rightGridTable.DefaultView.ToTable();

            epiUltraGrid.DataSource = rightGridTable;

It would be much easier to work with dataViews instead. One way to do it is using SetParentView :

// Lets say you've got 2 dataViews : edvChildView and edvParentView. When a record is 
// selected on edvParentView, you want edvChildView to filter.

EpiDataView edvChildView = ((EpiDataView)(this.oTrans.EpiDataViews["name of the child View in your form"]));
EpiDataView edvParentView = ((EpiDataView)(this.oTrans.EpiDataViews["name of the parent View in your form"]));

string[] parentKeyFields = new string[] { "PartNum", "RevisionNum"}; // list of fields to "join" from parent view
string[] childKeyFields = new string[] { "PartRev_PartNum", "PartRev_RevisionNum" }; // list of fields to "join" from child view
	         
edvChildView.SetParentView(edvParentView, parentKeyFields, childKeyFields); // set the relationship

Using Mathieu’s idea of using data views I managed to get something working.
I haven’t extensively tested it but from what I’ve tested so far in my use case there hasn’t been an issue.

	private void parentGrid_AfterRowActivate(object sender, EventArgs e)
{
    // Get the selected row from parent grid
    UltraGridRow selectedRow = parentGrid.ActiveRow;

    if (selectedRow != null && !selectedRow.IsGroupByRow)
    {
        // Get the value from the selected row 
        object obj = // Your type & value 

        // Filter based on what you need
        Filter(obj);
    }
}

private void Filter(Obj obj) // Replace obj with your type
{
    // Your dataview
    DataView dv = edvDv.dataView;

    // Apply a row filter
    dv.RowFilter = "Table_Field '" + obj.ToString("Format") + "'";
}

Thanks to @mbilodeau for the help

… and selectedRow should not be an UltraGridGroupByRow.

Thanks, edited the code block