EpiCombo and UserCodes

I’ve used EpiCombos cool little adapter search feature for a while now. It’s really handy and exceptionally so for UserCodes by just filtering the specific code type you want. I’ve ran into an issue that wanted to see if anyone has dealt with before.

In my current project I have a multipurpose field tied to various lookups. When I load a group of records, my custom field has various value types. The problem is, for invalid codes on other types, it still shows the items in the dropdown but with a (Code deleted) beside them. Before I started pouring over the decompiled EpiClient lib I wanted to see if anyone had some suggestions

image

First thought as the easiest approach is to catch BeforeDropDown and delete those items but I’d prefer a more sane solution.

Still looking for advice but here’s the route i took

private void cmbRegion_BeforeDropDown(object sender, System.ComponentModel.CancelEventArgs args)
	{
		// ** Place Event Handling Code Here **
		var sourceTable = (cmbRegion.DataSource as DataTable);
		var rowCount = sourceTable.Rows.Count;
		if(rowCount < 1) return;
		for(var i = rowCount -1; i >= 0; i--)
			{
				var row = sourceTable.Rows[i];
				 if(row["CodeDesc"].ToString().ToLower().Contains("(code deleted)")) row.Delete();
			}

			sourceTable.AcceptChanges();
	}
2 Likes

i am not following Chris, is filter Inactive record not working in your EpiCombo ?

I wasnt aware that was a thing. I’ll give it a try later. Thanks. At first glance, I dont think it will work, because the issue is not that the codes are inactive, they simply dont exist.

1 Like

where did you get them from, are you creating them -on the fly- ?? i.e. what are you binding the field to ?

How do they not exist and still show up on the dropdown?

Imagine 3 different combos pointed to 3 different user code types. All are saved\EpiBound to same field in a table. So there will be records within that field that do not exist in the UserCodes, i do not want these showing up in the dropdown.

If Field1 = “Dog”, Field2 dropdown contains Dogs.
If Field2 = “Cat”, Field2 dropdown contains Cats.

What happens is, when a list of records is loaded, for the values that do not exist in the User Codes, they show up with (Code deleted) beside them. As I mentioned, my code above solves the issue at hand.

hummm, i found this code example on the Stack website, no idea if you can use it in your case, but i imagine you need to put all of your possible -created on the UI Customization- values in a separate list (array), then apply this

  protected void YourListName_SelectedIndexChanged(object sender, EventArgs e)
        {
             if (YourListName.SelectedValue =="IndexNo.")
            {
                YourListName.Items.FindByValue("Keyword1").Enabled = false;
                YourListName.Items.FindByValue("Keyword2").Enabled = false;


            }
        }

@Chris_Conn I know you found a way around this and it’s old but in case someone stumbles on this, I used the code pattern below.

var myFilter = "(code deleted)";
UltraGridBand ugb = cmbRegion.DisplayLayout.Bands[0];

ugb.ColumnFilters["CodeDesc"].FilterConditions.Clear();   
ugb.ColumnFilters["CodeDesc"].FilterConditions.Add(FilterComparisionOperator.DoesNotContain, 
  myFilter); 
}
cmbRegion.Refresh();
cmbRegion.ActiveRow = cmbRegion.ActiveRowScrollRegion.FirstRow;

This code does helped out…thanks chris

1 Like

@Chris_Conn - I tried to use this and it works, but only after I clear two errors when clicking the drop-down arrow… incidentally, there are 2 items getting filtered out of the list. Is there a bit somewhere else I need to add to make it happy?

I dont believe you used the code above. Based on the error you got, you used a foreach() instead of a for()

You’re exactly correct. I did change it to a foreach. I didn’t realize that would affect anything. Everything affects something, I guess.

1 Like

Any time you use a foreach, you cannot add or delete from that collection as you are iterating

This is a big ask… but when I use your version, it doesn’t delete the rows. I must be overlooking something. No errors. But you can see those choices are still there in the list.
image

	private void cmbVehicleType_BeforeDropDown(object sender, System.ComponentModel.CancelEventArgs args)
	{
		// ** Place Event Handling Code Here **
				DataTable sourceTable = (cmbVehicleType.DataSource as DataTable);
				var rows = sourceTable.Rows;
				DateTime rdisDate = (DateTime) edvUD38View.dataView[edvUD38View.Row]["Date03"];
				int rowCount = rows.Count;
	/*
				foreach (DataRow eachRow in rows)
				{
					DateTime createDate = Convert.ToDateTime(eachRow["CreateDate"]);
					if (createDate > rdisDate)
					{
						eachRow.Delete();
					}
				}
				sourceTable.AcceptChanges();
	*/

				if (rowCount > 1) return;
				
				for (var i = rowCount - 1; i >= 0; i--)
				{
					DataRow row = sourceTable.Rows[i];
					DateTime createDate = Convert.ToDateTime(row["CreateDate"]);
					if (createDate > rdisDate)
					{
						row.Delete();
					}
				}
				sourceTable.AcceptChanges();
	}

if (rowCount > 1) return;

Why? This will bypass everything!

1 Like

I can’t express the level of facepalm that I am experiencing right now. I spent the better part of my afternoon yesterday trying all sorts of other things all because I started out with it wrong…

Thank you for pointing that out. I must’ve compared the two 15 times and never saw that error.