Hello,
i have unbound datagridview and i added autonumber in rows header.
I also added autonumber in first column cells but lets focus just on rows header.
Problem is when i sort the grid by values from some column the numbers in rows header lose order.
To be precise i want to have 1,2,3,4,5...ALWAYS in row header in that order,no mather what sorting i am doing on the grid.
Tried to find solution by changing again the row headers in grids events 'Sorted' and 'SortCompare' but with no luck.
Here is my code where on Initialisation i am adding some names from the list and autonumbers in first two columns and adding autonumbers to row header.
public Form3(List<string>; list, int brojkola)
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
dodajkolone(brojkola);
foreach (string igrac in list)
{
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[list.IndexOf(igrac)].Cells[1].Value = igrac;
int rednibroj = list.IndexOf(igrac);
this.dataGridView1.Rows[rednibroj].Cells[0].Value = rednibroj + 1;
setRowNumber(dataGridView1);
}
dataGridView1.Refresh();
}
private void setRowNumber(DataGridView dgv)
{
int broj = 1;
foreach (DataGridViewRow r in dgv.Rows)
{
r.HeaderCell.Value = (broj).ToString();
broj++;
}
}
Is there any way to prevent first column to be sorted when user sort on some other column or to prevent rows header to be sorted and stay always like autonumber 1,2,3,4...or is there any way after sorting by a column to put some code in some event to display numbers in row header in order i want.What event i should use for that.