Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • I have a grid that uses the RowValidating() event with a edit template. On the edit template, one of the fields is a combobox. If there is an error, when the edit template refreshes, the combobox value is empty. The items in the list are there, but the current value was cleared.

                                    In another article I saw something about calling the DataBindItems() method in the CellEditorInitialize() event, but this doesn't have any effect.

                                    Any idea why the combox doesn't get the current value after an error is trapped?

                                    Thanks.

                                0

                                Hi Brian:

                                Please try a solution suggested in the following report:

                                GridViewDataComboBoxColumn displays Value Field after grid validation

                                If this solution isn't helpful, please provide a sample illustrating the problem for more detailed research.

                                Thanks
                                Kate.

                                0

                                I tried to use your solution, but the code is all over the place and I can't get it working on my project. I have three grids on one form, and they all have inline editing. So now I'm trying to recreate the problem using an Access database (Xtreme.mdb from Crystal Reports demos) and I realize that I can't remember how I originally built the form a while back. So I'm looking through the site trying to find steps on how to build a form with inline editing using a combobox. I can find in-line examples, and a combobox example, but not inline edit/update using a combobox. Is there something like that on this site? So many examples, it's hard to find what I need.

                                Thanks.

                                0

                                Oh yeah - I should add that the combobox is not a simple text dropdown. It uses the ValueField and TextField properties. Right now I have it where when I check it during RowUpdating, it is returning the TextField value and not the ValueField (primary key). So I'm digging through all the knowledge base articles trying to figure out what I missed. But nowhere can I find a complete project which implements this. So far I'm just finding random code snippets that people show in their posts and nothing is complete. I'm sure you guys have a sample which demonstrates this, I'm just going blind trying to find it. ;-)

                                0

                                I managed to create a test project which demonstrates how the combobox loses it's value. I attached the test file.

                                Scenario 1: (Good values) Click the Edit button in the grid. Click the combobox and change it's value. Click the Update button to save changes. No errors will occur.

                                Scenario 2: (Bad values) Click the Edit button in the grid. Modify the date field. Click the Update button to save changes. The program now errors out on the line that tries to get the combobox current value. This is b/c it is now null. Thus, where my problem is.

                                In Scenario 2, how do I get the value from the combobox even though it wasn't modified? Right now it is always null unless I click on it to select a new value.

                                Thanks.

                                0

                                I took that project and added validation to it. This demonstrates my problem.

                                Test Case: Click the Edit button. Delete the Order Amount field (set to empty). Click Update.
                                Result: An error is displayed and the combobox loses its value.

                                Thanks for the help!

                                0

                                Hi Brian:

                                I'm working on your issue and will answer you as soon as possible. Please accept my apologies for the delay.

                                Thanks
                                Kate.

                                0

                                Thanks for letting me know. I was getting nervous that you guys were too backed up to work on it this week. :-)

                                0

                                Hi Brian:

                                I'm sorry for the delay.

                                In the current situation, I suggest that you check the following moments:

                                1) The ValueField of a combobox should correspond to the combobox column. I.e. values from this column should be represented as values of the combobox items. In your situation, values of the combobox are numbers, and values of the "Customer Name" column are strings. This approach is incorrect. Please change the ValueField of the combobox to "Customer Name" or any other field that contains all names of customers.

                                2) The ValueType of the ASPxComboBox should be equal to the type of values represented in the ValueField.

                                3) If these suggestions aren't helpful, please try to bind the combo in the Page_Load event handler as follows:

                                [C#]
                                protected void Page_Load(object sender, EventArgs e) { GridViewDataComboBoxColumn col = ASPxGridView1.Columns["Customer Name"] as GridViewDataComboBoxColumn; col.PropertiesComboBox.DataSource = GetCustomerTable(); ASPxGridView1.DataBind(); }

                                The following document describes the GridViewDataComboBoxColumn in detail:

                                GridViewDataComboBoxColumn Class

                                Thanks
                                Kate.

                                0

                                Thanks Kate,

                                I don't think I explained the example correctly. The Combobox's display text is the Customer Name, and it's primary key (the hidden value) is Customer Id. Thus, when it access the NewValues[] array, it should return the primary key (Customer Id) of that customer. When I implemented your suggestion, the NewValues[] array returns the CustomerName field (the display text), not the primary key.

                                I looked at the link you gave me, and in their example they set the TextField property to be CategoryName and the ValueField property to be CategoryID (the primary key). This is what I want to implement as well.

                                I made the following changes to my code to match the example in the link you sent me:
                                1. Set the ValueType = "System.Int32" to match the primary key of integer.
                                2. Added the Page_Load() code you told me to add.

                                The same problem occurs. I attached the project showing that my new code matches what is in the link you gave me. Can you look at this?

                                0

                                Hi Brian:

                                I assume that my explanation wasn't clear, so please accept my apologies for this inconvenience and let me describe the issue in greater detail.
                                Let's say, we have three scenarios:

                                1) I open the EditForm, select Nothing in the combobox and try to update the grid. The NewValue["Customer Name"] is null.
                                2) I open the EditForm. All editors have their values and the value in the combobox is set correctly. I clear the Order Amount field and try to update the grid. The server-side Validation is raised, the combobox refreshes it data and becomes... empty.
                                3) I open the EditForm, clear the Order Amount, select an item in the combobox and update the grid. The pervious selection is restored successfully, and now I get the correct NewValue["Customer Name"] if I fill the Order Amount field and update the grid again.

                                The trick is that scenarios 1 and 2 require the value from the "Customer Name" field for setting selection in the combobox. For example, if I open the first row, this field should contain the value 1. In this situation, the "City Cyclists" item will be selected in the combobox and the value will be equal to 1. For the second row, the "Customer Name" field should contain the value = 2 and so on.

                                In the third scenario, the previous selection is restored from the ViewState and the combo has a value.

                                So, if you wish to use the combo with the "Customer Id" ValueField in the "Customer Name" of the grid, you should set its initial selection manually using the CellEditorInitialize event handler. Otherwise, this editor will have a null value until you select an item.

                                If this explanation isn't clear and you have additional questions, please feel free to ask them.

                                Thanks
                                Kate.

                                0

                                Hi Kate,

                                This is starting to make more sense, but when I go into debug mode to look at the combobox properties, things don't match up. For example, here is the code for my combo box:

                                                <dx:GridViewDataComboBoxColumn FieldName="Customer Name" VisibleIndex="2">
                                                    <PropertiesComboBox TextField="Customer Name" ValueField="Customer Id"
                                                        ValueType="System.Int32">
                                                    </PropertiesComboBox>
                                                </dx:GridViewDataComboBoxColumn>

                                The display field is "Customer Name" and the ValueField is "Customer ID", the primary key. I also set the ValueType to be "System.Int32". But when I go into debug mode, this doesn't match up. I attached a screenshot of the CellEditorInitialize() event the first time it is called. Here are the important properties:

                                Text: Warsaw Sports, Inc (correct)
                                TextField: Customer Name (correct)
                                ValueField: Customer ID (correct)
                                Value: Warsaw Sports Inc (this should be the numeric id, not the name)
                                ValueFieldType: String (my code sets this as System.Int32 - why does it overwrite it with string?)

                                Clearly, something seems wrong here. I set the ValueField to be the ID and a datatype of number. Instead, it sets the type to be string and returns the customer name.

                                I've been programming for over ten years, and this combobox makes me feel like I'm a newbie. I followed the example in the link you gave me, but what it's showing me in debug mode doesn't make any sense.

                                Thanks,

                                Brian

                                0

                                Hello Brian,

                                Thank you for the clarification. I've reproduced the issue with your sample, but can't understand whether this is a bug or not.
                                I decided to forward the report to our developers, so they can examine it in greater detail. I hope that you will excuse me for a possible delay.

                                Thanks,
                                Vest

                                0

                                Hello Brian,

                                Our developers examined the issue, and found the thing that I hadn't noticed: you defined the FieldName property to be equal to the "Customer Name" field (or the String type). The ASPxGridView edits the Name, and not the ID.
                                The correct solution is to change the AcessDataSource Select command, so it will return "Customer Id" instead of "Customer Name".
                                If you wish to change the column's caption, you should edit the GridColumnEditFormSettings.Caption property.

                                Thanks,
                                Vest

                                0

                                The AccessDataSource currently returns both the Customer ID and the Customer Name. If I change it to only return the customer ID, then how will the user see the name in the dropdown box? They will only see the Customer ID, which doesn't mean anything to them.

                                When looking at the link you sent to me originally:
                                http://documentation.devexpress.com/#AspNet/clsDevExpressWebASPxGridViewGridViewDataComboBoxColumntopic

                                If you look at that link, they have the following properties set:
                                Property Link Example My App
                                ------------ ------------------ ------------------
                                TextField CategoryName Customer Name
                                ValueField CategoryID Customer ID
                                ValueType System.Int32 System.Int32

                                My application settings match the online sample's settings exactly. Yet, the combo box doesn't return the right data. How can it be that my sample app matches the online sample app exactly, but doesn't return the correct data? Can you guys modify the properties of my sample app so that it returns the Customer ID? Is this possible? It would be much faster for you guys to set the correct property in the sample app I sent you to show rather than sending these messages back and forth where it seems we are talking about different things.

                                Thanks,

                                Brian

                                0

                                Brian,

                                Probably, you are correct. Ok, I've modified your project, and implemented the required functionality in the easiest way.
                                Please take a look at the attachment.

                                Thanks,
                                Vest

                                0

                                Thanks for updating the solution! I will study this and see where I'm going wrong.

                                0

                                Hello Brian,

                                Feel free to reactivate the report, if you need my further assistance.

                                Thanks,
                                Vest

                                0

                                It works!!! What a relief to finally have this working. :-D

                                For anyone reading this in the future...The key piece of information that I was getting wrong is that the datasource for the main grid should not reference the child table at all (i.e. do not do an inner join to the child table). It should only reference the main table and use the Foreign Key (Customer ID) in its Select statement. Normally, this would pose a problem b/c I want my grid to show the Customer Name and not the Customer Id. The key piece that makes this work is that the dropdown box properties set the relationship between the Value Field (primary key of Customer ID) and Text Field (Customer Name). The dropdown box will make sure that the main grid displays the Customer Name, but behind the scenes it stores the Customer Id. Whew!

                                Thanks Kate for sticking with me through this one!

                                0

                                Oh yeah - Thanks Vest for updating my sample project and getting it to work. That let me see where I was going wrong.

                                0

                                You are welcome, Brian.

                                Thanks,
                                Vest

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners