DataGrid column displaying row index of DataSource

M

Maksman

Well, I'm having trouble setting myDataGrid to show ordinal position of row
in a DataSource in the first column (...say, like Excel does)

Code snippet follows:

....
myDataSet.Clear();
myDataSet.EnforceConstraints = false;
myDataAdapter = new SqlDataAdapter(mySelectCommand);
myDataAdapter.Fill(myDataSet, "MyTable");

FillRowNumColumn();


....
private int FillRowNumColumn() // Ver 1
{
int rowNum = 0;
foreach(MyDataRow myRow in myDataSet.MyTable)
{
myRow.rowNum = ++rowNum;
}
return rowNum;
}

private int FillRowNumColumn() // Ver 2
{
for(int rowNum = 1; rowNum <= MyTable.Rows.Count; ++rowNum)
{
myDataGrid[rowNum-1, 0] = rowNum;
}
return rowNum;
}

....

This does the job but performance dramatically decreases when dataTable
contains large amount of records (10.000 and more)

1. Is there a way to set the rowNum value without an extra 'FillRowNum'
method

2. How to add a column to DataGrid which displays just a line number of row.

Thanks

Maks
 
M

Maksman

Forgot to mention: it's about

System.Windows.Forms.DataGrid

... and NOT about

System.Web.UI.WebControls.DataGrid

Maksman
 

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

Top