Automatic row number for Silverlight

Source: Internet
Author: User

First, check the effect.

Ideas:

Add a template column to the first column of each DataGrid, which defines only one textblock

In the row loading event of the DataGrid, add a number to the textblock of each row.

XAMLCode:

View code

    <  Data: DataGrid  X: Name  = "Gridlist"  Grid. Row  = "0"  Margin  = "5, 0, 5, 0"  Gridlinesvisibility = "All"   
Autogeneratecolumns = "False"
Frozencolumncount = "1"
Arerowdetailsfrozen = "True"
Horizontalalignment = "Stretch" Canusersortcolumns = "False"
Itemssource =" {Binding invstocklistmodellist, mode = twoway} "
Isreadonly = "True" Selecteditem =" {Binding invstocklistmodel, mode = twoway} " >

< Data: DataGrid. Columns >
< Data: datagridtemplatecolumn Header = "No" >
< Data: datagridtemplatecolumn. celltemplate >
< Datatemplate >
< Textblock />
</ Datatemplate >
</ Data: datagridtemplatecolumn. celltemplate >
</ Data: datagridtemplatecolumn >
< Data: datagridtextcolumn Header = "Item name" Binding =" {Binding materialmodel. mat_name, mode = twoway} " />
< Data: datagridtextcolumn Header = "Repository name" Binding =" {Binding storgemodel. storge_name, mode = twoway} " />

< Data: datagridtextcolumn Header = "Location name" Binding =" {Binding invlocationmodel. location_name, mode = twoway} " />
< Data: datagridtextcolumn Header = "Batch number" Binding =" {Binding stocklist_batch, mode = twoway} " />
< Data: datagridtextcolumn Header = "Year" Binding =" {Binding stocklist_year, mode = twoway} " />
< Data: datagridtextcolumn Header = "Accounting period" Binding =" {Binding stocklist_period, mode = twoway} " />
< Data: datagridtextcolumn Header = "Revenue amount" Binding =" {Binding stocklist_iamount, mode = twoway} " />
< Data: datagridtextcolumn Header = "Unit price" Binding =" {Binding stocklist_iprice, mode = twoway} " />
< Data: datagridtextcolumn Header = "Income amount" Binding =" {Binding stocklist_imoney, mode = twoway} " Width = "100" />
< Data: datagridtextcolumn Header = "Number of outgoing mails" Binding =" {Binding stocklist_oamount, mode = twoway} " />
< Data: datagridtextcolumn Header = "Unit price issued" Binding =" {Binding stocklist_oprice, mode = twoway} " />
< Data: datagridtextcolumn Header = "Amount issued" Binding =" {Binding stocklist_omoney, mode = twoway} " Width = "100" />
< Data: datagridtextcolumn Header = "End number" Binding =" {Binding stocklist_endamount, mode = twoway} " />
< Data: datagridtextcolumn Header = "End amount" Binding =" {Binding stocklist_endmoney, mode = twoway} " Width = "100" />
< Data: datagridtextcolumn Header = "Supplier batch number" Binding =" {Binding stocklist_suppbatch, mode = twoway} " />
</ Data: DataGrid. Columns >
</ Data: DataGrid >

CS code:

View code

 Public  Invstocklistview ()
{
Initializecomponent ();
Gridlist. loadingrow + = New Eventhandler < Datagridroweventargs > (Gridlist_loadingrow );
}
Void Gridlist_loadingrow ( Object Sender, datagridroweventargs E)
{
VaR Index = E. Row. getindex ();
VaR Cell = Gridlist. Columns [ 0 ]. Getcellcontent (E. Row) As Textblock;
If (Cell ! = Null ) Cell. Text = (Index + 1 ). Tostring ();
}

Success !!!

author: memories of lost youth
Source: http://www.cnblogs.com/lukun/
copyright of this Article It is shared by the author and the blog site. You are welcome to repost it, but this statement must be kept without the author's consent, and in the Article page obvious position to give the original connection, if there is a problem, you can contact me through the http://www.cnblogs.com/lukun/ , thank you very much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.