enumerator in gridview

In VS2005 winforms C# I have a datagridview binding to a dataset.
I want to see in the gridview a new column that will be an enumerator that will show the number of the row
starting from 1. I want that if I delete a row this enumerator will update. How can I implement this?
Who is Participating?
ANAT2403Connect With a Mentor Author Commented:
I solved this question in a method that I added to a user control on paging datagridviw.
this is the user control
and this is the code I added
 /// <summary>
        /// Sets and displays a DataTable
        /// this also add a new column with the row number
        /// </summary>
        /// <param name="dtin">The DataTable to display.</param>
        public void SetDataTablewithRowNumber(DataTable dtin)
            int indrow,indcol;
            int maxr = dtin.Rows.Count;
            DataTable tempdt = new DataTable();
            System.Data.DataRow drnew;
            int numcol = dtin.Columns.Count;
            tempdt.Columns.Add("Row", Type.GetType("System.Int32"));
            for (indcol = 0; indcol < numcol; indcol++)
                tempdt.Columns.Add(dtin.Columns[indcol].ColumnName, dtin.Columns[indcol].DataType);

            for (indrow = 0; indrow < maxr; indrow++)
                drnew = tempdt.NewRow();
                drnew["Row"] = indrow+1;
                for (indcol = 0; indcol < numcol; indcol++)
                    drnew[dtin.Columns[indcol].ColumnName] = dtin.Rows[indrow][dtin.Columns[indcol].ColumnName];
Gautham JanardhanCommented:
check this out

DataTable FTable =
                        new DataTable();
                  FTable.Columns["COL3"].Expression = "COUNT(COL1)";

                  DataRow FRow = FTable.NewRow();
                  FRow["COL1"] = "1";
                  FRow["COL2"] = "1";

                  object obj = FTable.Rows[0]["COL3"];

col3 would give u the count
Gautham JanardhanCommented:
u can bind a similar column to the grid voew so that it ill always show the count
ANAT2403Author Commented:
Sorry I don't get you and I asked for an example with a gridview.
Gautham JanardhanCommented:
if u bind the column 'COL3' to a column in a grid view that column will always show the count
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.