Ticket Q411913
Visible to All Users

Set default value of RepositoryItemComboBoxEdit

created 13 years ago

Hi,
I'm using a RepositoryItemComboBoxEdit as in-place editor for one of the column in my XtraGrid. I assigned the repository item to the ColumnEdit property for this column in design mode. From backend I'm receiving a semi-colon seperated string with value (ex: "1,2,3,4"). On the ShownEditor event, I'm splitting this string and adding these as individual items of the repositorycombobox item as below

ComboBoxEdit cmbPO = gvDetail.ActiveEditor as ComboBoxEdit;
int currentRow = view.FocusedRowHandle;
string groupPoNumberList = detailList[currentRow].GroupPoNumber;
if (!string.IsNullOrEmpty(groupPoNumberList))
{
if (groupPoNumberList.IndexOfAny(semiColon) >= 0)
{
cmbPO.Properties.Items.AddRange(groupPoNumberList.Split(','));
} }}

All that I want to do is set the default value of this comboboxedit as the first item that I'm adding here. I tried using SetRowCellValue and set the value as the first value in LoadControl method, but it doesn't work.

Please suggest.

Answers

created 13 years ago (modified 13 years ago)

Hi,
Thank you for contacting us.
If I understand you correctly, you need to set some predefined value in the activated comboBoxEdit editor.
You can implement it directly in the GridView.ShownEditor event handler.
Specify the ComboBoxEdit.SelectedIndex property value to some existing index. For example:

C#
private void gridView1_ShownEditor(object sender, EventArgs e) { GridView currentView = sender as GridView; ComboBoxEdit cmbPO = currentView.ActiveEditor as ComboBoxEdit; //............. if (cmbPO.Properties.Items.Count > 0) { cmbPO.SelectedIndex = 0; } }

It is also possible to invoke the GridView.SetRowCellValue method. But this method results in immediate posting a cell value, instead of positioning ComboBoxEdit's selected value.

C#
private void gridView1_ShownEditor(object sender, EventArgs e) { GridView currentView = sender as GridView; ComboBoxEdit cmbPO = currentView.ActiveEditor as ComboBoxEdit; //............. object currentValue = currentView.GetRowCellValue(currentView.FocusedRowHandle, currentView.FocusedColumn); if (currentValue != null) { currentView.SetRowCellValue(currentView.FocusedRowHandle, currentView.FocusedColumn, cmbPO.Properties.Items[0]); } }

If neither of these approaches can be implemented in your scenario, please describe in greater detail the following points: your final goal, in which manner you obtain data for ComboBoxEdit, and control interaction in your working application.
I am looking forward to your response.

    Show previous comments (3)
    Andrew Ser (DevExpress Support) 9 years ago

      Hello,
      >> Right now it defaults to blank and lets the user choose.
      Do you mean that VGridControl's cell is initially empty or it becomes empty when you activate ComboBoxEdit?
      In the former case, you need to assign the required value to the grid cell (the RepositoryItemComboBoxEdit presence doesn't matter). This value comes from a data source. If it is empty and you want to set it, call the VGridControl.SetCellValue method.
      In the latter case, the approach Oleg described should be helpful. VGridControl has the ShownEditor event as well.
      I hope you find this information useful.

        Thanks Andrew. I was thinking I had to set the cell value to an object of the RepositoryItem collection. Setting it to a string works fine.

        Andrew Ser (DevExpress Support) 9 years ago

          You are welcome! Feel free to contact us if you have any questions.

          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.