I have a Datatable
DataTable dt = new DataTable();
dt.TableName = "Player";
dt.Columns.Add("PlayerNo", typeof(int));
dt.Columns.Add("[2PMissed]", typeof(int));
dt.PrimaryKey = new[] { dt.Columns["PlayerNo"] };
and I fill the rows from a list "Homelist"
dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4);
for (int i = 0; i < Homelist.Count; i++)
{
dt.Rows.Add(Homelist[i].Key, Homelist[i].Value, Homelist[i].Value.Substring(0, 2), 0);
}
Also there is another list "events".I get an int value and store it to "plId". I want to get the index of the row of Datatable "dt" where the column "PlayerNo" of dt is equal to "plId" variable.
int plId = events[i].PlayerId;
int index = dt.Rows.IndexOf(dt.Rows.Find(plId));
The PlayerNo column gets unique values(is ID).
I change the datatable definition and I use primary key.Then I use find() method and fix the problem as here Get the row next to the row got with DataTable.Select()