Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Auto fill
posted

I have just study WPF for short time. So I need a help below : I have a XamDataGrid with 4 columns. One of them is "Order ID". I used AllowAddNew="True" to add new column. So I want to when click Add icon, Order ID field will display a string automatically.How can I do this ? I used VB.NET and datbase is SQL Server 2008

  • 8421
    Suggested Answer
    posted

    Hello,

    One way to accomplish this is to handle the PreviewMouseDown event on the XamDataGrid and then check to see if the item clicked is a RowSelector object that has its IsAddRecord property set to true. If it is, then extract the DataRecord from the RowSelector and set the Value of the OrderID cell to the string value that you want. I have attached a small sample that demonstrates doing this and uses Northwind as its data provider.

    Please note that what you use to populate the cell is going to be dependent on your needs. In my sample I made the assumptions that I would want to increase the ID by one with each new record and that the OrderID column would be sorted in the correct order. With these assumptions in mind I extracted the OrderID of the last item in the Orders table.

    XamDataGridAddIncrement.zip