By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,465 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,465 IT Pros & Developers. It's quick & easy.

How to Display line number in the datagrid ?

P: n/a
Hi :
When i display the DataBase in System.Windows.Forms. DataGrid ,i want to
display the line number of ever line .How can i do it ?
Any help may be Good .
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

You can probably do so by implementing a custom DataGridColumnStyle with
overridden methods responsible for retrieving data from and updating data in
the bound datasource. The retrieval method will simply return the passed row
number, and the update method will not obviously update anything.

An alternative way could be doing custom drawing on row headers by
post-processing the grid's Paint event.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"BlueFox" <li*******@boco.com.cn> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...
Hi :
When i display the DataBase in System.Windows.Forms. DataGrid ,i want to display the line number of ever line .How can i do it ?
Any help may be Good .


Nov 15 '05 #2

P: n/a
It is very easy for the Data Grid Control there is an event called
"ItemDataBound"

Register a function for that event.

In the body of that function write the following code

if(e.Item.ItemType != ListItemType.Header)
e.Item.Cells[0].Text = "" + (e.Item.DataSetIndex + 1);

That's it. You will get line numbers.

regards,
Abhishek.

BlueFox wrote:
Hi :
When i display the DataBase in System.Windows.Forms. DataGrid ,i want to
display the line number of ever line .How can i do it ?
Any help may be Good .

Nov 15 '05 #3

P: n/a
I didn’t describe what I want very well.What I really want is to display
the line number of every line before the first column of DataGrid.They will
do not change even if user sort the datatable by click the DataGrid’s
header.

My English is poor,I can’t describe my mean exactly.

Thank you for you help.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> 写入消
息 news:Ox**************@TK2MSFTNGP11.phx.gbl...
Hi,

You can probably do so by implementing a custom DataGridColumnStyle with
overridden methods responsible for retrieving data from and updating data in the bound datasource. The retrieval method will simply return the passed row number, and the update method will not obviously update anything.

An alternative way could be doing custom drawing on row headers by
post-processing the grid's Paint event.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"BlueFox" <li*******@boco.com.cn> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...
Hi :
When i display the DataBase in System.Windows.Forms. DataGrid ,i
want to
display the line number of ever line .How can i do it ?
Any help may be Good .

Nov 15 '05 #4

P: n/a
You should override the OnPaint method then and render row numbers on row
headers, hence you should also ensure the row headers are visible by setting
the appropriate property(ies) in the inherited grid's constructor.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"BlueFox" <li*******@boco.com.cn> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
I didn’t describe what I want very well.What I really want is to display
the line number of every line before the first column of DataGrid.They will do not change even if user sort the datatable by click the DataGrid’s
header.

My English is poor,I can’t describe my mean exactly.

Thank you for you help.


Nov 15 '05 #5

P: n/a
I will try it.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> 写入消
息 news:#n**************@TK2MSFTNGP09.phx.gbl...
You should override the OnPaint method then and render row numbers on row
headers, hence you should also ensure the row headers are visible by setting the appropriate property(ies) in the inherited grid's constructor.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"BlueFox" <li*******@boco.com.cn> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
I didn’t describe what I want very well.What I really want is to display the line number of every line before the first column of DataGrid.They

will
do not change even if user sort the datatable by click the DataGrid’s
header.

My English is poor,I can’t describe my mean exactly.

Thank you for you help.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.