How to renumber cell content in DataGridView column

  • Thread starter Thread starter Tim Sprout
  • Start date Start date
T

Tim Sprout

I have about a year's experience with C#.

How can one rename a column of cell value numbers
from an Access database in a DataGridView?

Say, have:

4
3
6
5
8
7

as cell values,

want:

1
2
3
4
5
6




Thanks,

--Tim Sprout
 
Tim,

It looks like you want to use something like the ROW_NUMBER ranking
function in SQL. Unfortunately, Access doesn't have anything like that.

Once you get the data table from the access database, you will have to
add a column to the data table which will hold your order. You then cycle
through the records, setting the column value, and incrementing your
counter.

Then you would work with your new counter.
 
I used the code below to load the desired column in ascending order.
I could then cycle through the cell values and renumber sequentially.
I guess this bypasses the default loading of sorting by key value.

da.Fill(dt);
dataGridView1.DataSource = dt;
DataGridViewColumn newColumn = dataGridView1.Columns[1];
dataGridView1.Sort(newColumn, ListSortDirection.Ascending);

Thank you.

--Tim Sprout


Nicholas Paldino said:
Tim,

It looks like you want to use something like the ROW_NUMBER ranking
function in SQL. Unfortunately, Access doesn't have anything like that.

Once you get the data table from the access database, you will have to
add a column to the data table which will hold your order. You then cycle
through the records, setting the column value, and incrementing your
counter.

Then you would work with your new counter.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tim Sprout said:
I have about a year's experience with C#.

How can one rename a column of cell value numbers
from an Access database in a DataGridView?

Say, have:

4
3
6
5
8
7

as cell values,

want:

1
2
3
4
5
6
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top