By Andria Jensen - 7/11/2006
I have a combobox which has a BindingField that updates when a corresponding grid row is selected. The combobox is really a dropdown (non-editable), and displays a queried list depending on other selections. If no selection is made from the dropdown I want a blank to show. This works okay until I select one that has a value showing in the dropdown. After this, every blank value shows as the previous record's value instead of blank. I think the issue is that when the record changes, and the new record has a blank field it is looking for a blank in that dropdown, but doesn't find it so it just stays on the current field. I may be confusing the point here, but if you understand my question a solution to this problem would be great. Thanks!
|
By Trent L. Taylor - 7/11/2006
Are you using a TopMostItem in the combo box? You should use a TopMostItem and set the value property to represent the "blank" record. This will allow the binding to work properly and set the combo back to an empty value. You can also set the SelectedValue property of the combo manually to the "blank" value which will reset the list as well.
|
By Andria Jensen - 7/11/2006
I put a TopMostItem property in and am now using the following code:With Me.cboRule1Code .DataSource = DebRateCodeBO.GetDataTable(ComboSource) .TopMostItem.TopMostDescription = "<none>" .TopMostItem.TopMostValue = "" .Refresh() End WithI am still getting the same results as before. I see no "<none>" value in the dropdown. Is there something else I need to do to make this work? Or is something possibly overriding this?
|
By Trent L. Taylor - 7/11/2006
What is your binding field and what data type is it?
|
By Andria Jensen - 7/11/2006
I have a data field called RateCode and it is a string.
|
By Trent L. Taylor - 7/11/2006
With Me.cboRule1Code .DataSource = DebRateCodeBO.GetDataTable(ComboSource) .TopMostItem.TopMostDescription = "<none>" .TopMostItem.TopMostValue = "" .Refresh() End With Are you ever setting the DisplayMember and the ValueMember properties of the combo box? This is how the combo knows how to bind to data assuming that your BindingProperty is set to SelectedValue. For example: With Me.cboRule1Code .DisplayMember = "RateCode" .ValueMember = "RateCode" .DataSource = DebRateCodeBO.GetDataTable(ComboSource) .TopMostItem.TopMostDescription = "<none>" .TopMostItem.TopMostValue = "" .Refresh() End With
|
By Andria Jensen - 7/11/2006
I am setting the DisplayValue and ValueMember at runtime to "RateCode". The binding seems to be working fine, as it will select the value if it is not blank. It's just getting it to show a blank in the combo when blank is in the selected record that is the problem.
|
By Trent L. Taylor - 7/11/2006
Is there padding your the field RateCode? If it is a Char field, this may be your problem as the value is an empty string. You might check to see if the data behind the "blank" field is a zero length string.
|
By Andria Jensen - 7/11/2006
I think maybe I need to explain further and you can tell me if I'm doing this the wrong way. I have a BusinessObject with fields called Rule1Code, Rule2Code, Rule3Code, etc. Each of these has a combo box which is populated by a SQL Select from a different table than the BO looks at, and its field is RateCode. Each of the combo boxes are then bound to the BO and the BindingField set to Rule1Code, Rule2Code, etc. Could any of this be part of my problem and is there a better way to do this?
|
By Andria Jensen - 7/11/2006
Oh, and RateCode is an nvarchar of length 1 and the blank values are actually empty strings("") and not NULL values. Rule1Code, Rule2Code, etc. are set up the same way in the other table which the BO is mapped to.
|
By Trent L. Taylor - 7/11/2006
I will have to setup this scenario and test it. I will let you know when I know something.
|
By Andria Jensen - 7/11/2006
Thanks for the help Trent, I look forward to hearing from you!
|
By Andria Jensen - 7/13/2006
Has anything been figured out with this issue?
|
By Trent L. Taylor - 7/13/2006
Andria,Sorry I haven't gotten back with you. I have been overrun this week. I will look at this in the morning and get something to you. 
|
By Andria Jensen - 7/14/2006
That's okay...I know what you mean. I've got lots to do myself which is the only reason this is important to me at the moment. Thanks for the help!
|
By Trent L. Taylor - 7/14/2006
Andria,Attached is a simple example of a character based topmost item. I am not using a bound field to simplify the example, but if you have a bound field it will work in the same fashion. To see how the sample works, run the solution and the select a value other than the topmost item. Once a valid customer name has been selected, click the button to force the SelectedValue back to the top most item. The concept of a bound value is the same. Instead of manually setting the SelectedValue, the binding will set it for you when the bound record is navigated to a value that matches the top most value. Let me know if you have any questions. 
|
By Andria Jensen - 7/14/2006
Ok, that works for the SF combobox, but did I forget to mention that I was using a DevX Inherited Combo? I have included the sample you did with an added DevX SF combo. I set it up the same as the SF combo, but the topmost property doesn't work correctly. I put the TopMostItem property setting in the Form Load event, because when I tried to set it at design time for the DevX control, it gave me an error. Please see if you can figure anything out with these behaviors. Thanks.
|
By Trent L. Taylor - 7/14/2006
Andria,In your DevExpress combo you have the Value Member set to the cust_pk which is integer. But the TopMostItem's value is empty which would make it a string. Thus the error you are getting. The type of value member and the type of TopMostItem have to match. If you set the Value Member in the PopulationDataSourceSettings to cust_lname which is the value I wanted to associate with the combo box, then it will work fine. 
The value member in the PopulationDataSourceSetting is the value that gets assigned to a bound value. So in your previous posts you mentioned that the bound value is a string field called RateCode. So your value member should be RateCode. If you are creating custom properties such as RateCode1, the this would be your value member. Let me know if this answers your question.
|
By Trent L. Taylor - 7/14/2006
Andria,One other thing, instead of setting the TopMost property in the load, use the property within the property sheet. It will work much better since it will load it into the data source with the rest of the records. Otherwise it may not work at all depending on the order of instantiation. 
|
By Andria Jensen - 7/14/2006
Great! I got it working finally...I must have just been overlooking the Value Member in the Data Source Setting. I was actually trying to set the DataSource to a table manually, but it worked much better after i created a BO and had it do the work for me. I just have one other question along these same lines...I have a textbox that is bound to an integer value. If I want it to show a blank unless there is a nonzero value how do I go about doing that?
|
By Trent L. Taylor - 7/14/2006
Since you are using the DevExpress controls, use the EditMask. If you set the EditMask to ###, for example, and a MaskType of Numeric, it will by default hide any zero values. You may decide to use the DisplayMask instead. But you can do it through masking.
|