EpiDataView Row not Selected after records returned

Can anyone tell me how this can be happening? I have a function to retrieve records from a UD table and select the first row if count > 0. Number of rows returned is correct, however, the edv.row is still being set to -1 instead of 0.
image image

	private void GetStructureData()
	{
		DataRow parentViewRow = this.edvProject.CurrentDataRow;
		if(parentViewRow == null)
		{
			parentViewRow = this.edvProject.dataView.Table.Rows[0];
		}
		string projID = parentViewRow["Key1"].ToString();
		// Build where clause for search.
		string whereClause = "Key1 = \'" + projID + "\'";
		System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
		whereClauses.Add("UD11", whereClause);

		// Call the adapter search.
		SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
		this.StructureAdapter.InvokeSearch(searchOptions);
EpiMessageBox.Show("Count: " + this.StructureAdapter.UD11Data.UD11.Rows.Count);
		if ((this.StructureAdapter.UD11Data.UD11.Rows.Count > 0))
		{
			this.edvStructure.Row = 0;
EpiMessageBox.Show("Row: " + this.edvStructure.Row);
		} else
		{
			this.edvStructure.Row = -1;
		}
		// Notify that data was updated.
		this.edvStructure.Notify(new EpiNotifyArgs(this.oTrans, this.edvStructure.Row, this.edvStructure.Column));
	}

I’d be curious to test the:
this.edvStructure.dataView.Count

If it doesnt have any records, it may not allow > -1

You are on to something, the dataView.Count does come up as 0. How should this be addressed?

I assume this an edv you created? Is it linked to anything? Can you share where it is created?

In context, I think you are wanting it kinda like this:
var myEdv = new EpiDataView(this.StructureAdapter.UD11Data.UD11);

Correct. This function is called from InitializeCustomCode().

private void InitializeStructure()
{
	// Create an instance of the Adapter.
	this.StructureAdapter = new UD11Adapter(this.oTrans);
	this.StructureAdapter.BOConnect();

	this.edvProject = ((EpiDataView)(this.oTrans.EpiDataViews["UD10"]));

	// Add Adapter Table to List of Views
	// This allows you to bind controls to the custom UD Table
	this.edvStructure = new EpiDataView();
	this.edvStructure.dataView = new DataView(this.StructureAdapter.UD11Data.UD11);
	this.edvStructure.AddEnabled = true;
	this.edvStructure.AddText = "New Structure";
	if ((this.oTrans.EpiDataViews.ContainsKey("StructureView") == false))
	{
		this.oTrans.Add("StructureView", this.edvStructure);
	}

	// Initialize DataTable variable
	this.Structure_Column = this.StructureAdapter.UD11Data.UD11;

	// Set the parent view / keys for UD child view
	string[] parentKeyFields = new string[1];
	string[] childKeyFields = new string[1];
	parentKeyFields[0] = "Key1";
	childKeyFields[0] = "Key1";
	this.edvStructure.SetParentView(this.edvProject, parentKeyFields, childKeyFields);

	if ((this.oTrans.PrimaryAdapter != null))
	{
		// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this.edvStructure.dataView.Table.Clone())
	}
}

One other note: I have the UD11 table set up as a child table of UD10. This case only happens when I use the native search to select an existing UD10 record. If a known value is entered, everything loads correctly. With more than one UD10 record selected, changing rows in the UD10 view works. Changing rows in the UD11 view works. This only occurs initially when UD10 record(s) are selected using the native search.

I’d bet a cheap beer that the issue is caused by the parent\child relationship. Since the UD11 is filtered by its UD10 parent, it’s like the notification hasnt happened yet on the parent to tell the child what it should see. If you wanted a dirty test, just temporarily disable the parent\child.

On how to solve it, perhaps some sort of notify is needed - perhaps you could get away with settings the UD10 row manually and notifying first.