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?
Thankyou
Anat
ANAT2403Asked:
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
http://www.codeproject.com/useritems/Paging_DataGridView.asp
and this is the code I added
Anat
 /// <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];
                }
                tempdt.Rows.Add(drnew);
            }
 
            dsTemp.Tables.Add(tempdt.Copy());
            GoToPageNumber(1);
        }
0
 
Gautham JanardhanCommented:
check this out

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

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

                  object obj = FTable.Rows[0]["COL3"];
                  Console.WriteLine(obj.ToString());

col3 would give u the count
0
 
Gautham JanardhanCommented:
u can bind a similar column to the grid voew so that it ill always show the count
0
 
ANAT2403Author Commented:
Sorry I don't get you and I asked for an example with a gridview.
Anat
0
 
Gautham JanardhanCommented:
if u bind the column 'COL3' to a column in a grid view that column will always show the count
0
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.