So here is my Code that is able to get the header of the datagrid column and find the matching values from the user inputs. For Example if input is "jdoe" it will look at the Username column in the datagrid and match the [value.Key].Text to the value.Value. Now the problem is that each row has an "Edit" button with the same automation ID. How do I iterate through the datagrid and be able to click on the Edit button with regardless of what row "jdoe" is in: Here is what I have so far:
public static bool Contains(this ListView listView, ObjectInList objectInList)
{
foreach (ListViewRow row in listView.Rows)
{
if (DataMatches(row, objectInList))
return true;
}
return false;
}
private static bool DataMatches(ListViewRow row, ObjectInList objectInList)
{
foreach (KeyValuePair<string, string> value in objectInList.Values)
{
if (row.Cells[value.Key].Text != value.Value)
return false;
}
return true;
}
}
internal class UserInList : ObjectInList
{
public UserInList(string username)
{
_values["Username"] = username;
}
}
internal class OrderInList : ObjectInList
{
public OrderInList(string orderNumber)
{
_values["Depot Tag #"] = orderNumber;
}
}
internal abstract class ObjectInList
{
protected readonly Dictionary<string, string> _values = new Dictionary<string, string>();
public IReadOnlyDictionary<string, string> Values
{
get { return _values; }
}
This is a screenshot of the WPF application