Ticket Q459855
Visible to All Users

executeStoreQuery as GridView source and adding new row with own sql

created 12 years ago

Dear support,
I really cannot find how to insert something to gridcontrol. Here are some incomplete code. In short, pe (the linq to entity) run the sql and use the result as the datasource of a gridcontrol. I allow the user to add new row to this gridcontrol
The question is. 1. i can see the new row at bottom. But when i input the text in 1 cell, and move to another cell, the text i type before is cleared. 2. if i use my own sql to insert the data back to db. what event in the gridcontrol will fire so that i can put my insert code.

// a long long SQL
string sql2 = @"SELECT v.VndrID AS [VendorNo] , v.Cmpny AS [CompanyName] , vp.PdtID AS [MaterialNo] , vp.PdtDscp AS [MaterialDescription] , p.ColorID AS [ColorNumber] , p.ColorNm AS [ColorName] , vp.LeadTime AS [LeadTimeDays] , vp.CostRate AS [Cost]FROM PdtColorVndr p LEFT JOIN Vndr v ON p.slkVndr = v.prmykey LEFT JOIN VndrPdt vp ON vp.prmykey = p.slkVndrPdtWHERE p.prntkey = @colorkeyORDER BY v.VndrID";

// set parameter
var sql2Params = new SqlParameter[] { new SqlParameter("colorkey", row.prmykey) };

// set it to gridcontrol data source
gridControl1.DataSource = pe.ExecuteStoreQuery<PdtColorVendor>(sql2, sql2Params);
Finally, I purchased DX perience 12.1. I cannot find it in your product list. But i think it is related to xtragrid suite

Comments (3)
DevExpress Support Team 12 years ago

    Posting multiple questions within a report makes it difficult to properly track and process such items.
    In order to better serve you and track multiple questions in your inquiry, we have taken the liberty of separating the issues you addressed. For quick and efficient responses to your concerns, we kindly request that future inquiries address one issue at a time. Your time and cooperation are appreciated.

    1. Q371302
      Please refer to this report for further correspondence on this item.
    DevExpress Support Team 12 years ago

      Hi Hak,
      Thank you for contacting us. Our GridControl uses the same mechanism as the standard DataGridView to bind data. Try to bind your data source to the standard DataGridView control. If you have the same result, this means that your data source is not valid. In fact, our GridControl has one main requirement: your datasource must support the IList, IListSource, ITypedList, or IBindingList interface.
      If you wish, we can research your application in greater detail. Just send us a simple example that illustrates your approach.
      The most appropriate way to update your data is to use the GridView.RowUpdated event.
      If you need additional assistance, feel free to reactivate this topic.

        Thank you for your answer. ExecuteStoreQuery return ObjectResult<SomeClass>. ObjectResult is implementing ITypedList. As a result, the return value of ExecuteStoreQuery can be used a data source of GridControl. I make a very very simple application to show my problem. You cannot directly run as you dont have the database. You can add your own database and change the form a little bit. My form just have 2 lines of code and define a class to hold the result

        1. It shows a new row at bottom. But when i type something in POID row and go to description row, the text i type in POID row disappear.
        2. If i want to use a insert sql to insert the 2 values inputted. What event i should catch. I need to solve quetion 1 first in order to test your suggestion (RowUpdated event)

        Answers approved by DevExpress Support

        created 12 years ago (modified 12 years ago)

        Hi Alex,
        As described in the ColumnView.AddNewRow Method help topic, a grid datasource must support the IBindingList interface to which the Grid can add a new record. In your case, the datasource does not support it. So, it's impossible to use the Grid interface to add a new record.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.