Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:51:10+00:00 2026-05-25T13:51:10+00:00

Error: Index was out of range Must be non-negative and less than the size

  • 0

Error: Index was out of range Must be non-negative and less than the size of the collection

I have a customized LookUpEdit –

public class MyLookUpEdit : LookUpEdit

I refer to the following link to add MyLookUpEdit to a ribbon. Now MyLookUpEdit is available in my ribbonPageGroup–>Add Editor.

http://www.devexpress.com/Support/Center/KB/ViewKBIssue.aspx?kbid=A1237

Here is the InitializeControl Method for MyLookUpEdit:

public void InitializeControl(ICollection cache, string columnField1, string columnField2, string valueField, bool isMultiColumn, int searchColumn)
        {
            Properties.ForceInitialize();
            const int maxDropDownSize = 7;
            Properties.Columns.Clear();

        if(isMultiColumn)
        {
                Properties.Columns.AddRange(new[] {
                new LookUpColumnInfo(columnField1, columnField1, columnField1.Length*6, FormatType.None, "", true, HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None),
                new LookUpColumnInfo(columnField2, columnField2, 100, FormatType.None, "", true , HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None)});
                Properties.ShowHeader = true;
                Properties.PopupFormMinSize = new Size(0, 0);
                Properties.AppearanceDropDownHeader.TextOptions.HAlignment = HorzAlignment.Near;
                Properties.AutoSearchColumnIndex = searchColumn;
        }
        else
        {
                Properties.Columns.AddRange(new[]{
                new LookUpColumnInfo(columnField1, columnField1, 10, FormatType.None, "", true, HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None),
                new LookUpColumnInfo(columnField2, columnField2, 0, FormatType.None, "", false , HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None)});
                Properties.ShowHeader = false;
                Properties.PopupFormMinSize = new Size(10, 10); // set popup width to control width

                break;
        }

        Properties.ShowFooter = false;
        Properties.ShowLines = true;
        Properties.ValueMember = valueField;
        Properties.DisplayMember = columnField1;
        Properties.DataSource = cache;
        if (cache == null) return;
        Properties.DropDownRows = cache.Count > maxDropDownSize ? maxDropDownSize : cache.Count;

        ColumnBestFit();
        HideIcon();
    }

But at the run time, in ribbon, I cannot click the button and see all available values for the lookupedit – it looks like the popup is not open, and when I leave the edit, the following code throw the error:

    protected override void OnLeave(EventArgs e)
    {
        if (IsPopupOpen) 
        {
            ItemIndex = PopupForm.SelectedIndex;
            _selectfromPopup = true;
        }
    Properties.DisplayMember = Properties.Columns[0].Caption; // This line throw the error

        base.OnLeave(e);

        if (textChanged)
            OnLeaveWithChangedText(e);

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:51:10+00:00Added an answer on May 25, 2026 at 1:51 pm

    there could be different reasons why the columns list is empty, it depends on the whole form events and methods chain and whatsoever, but to be sure and use a defensive approach (my swiss army knife 😉 )

    just put a check before:

    Properties.DisplayMember = Properties.Columns[0].Caption;
    

    so to execute that row only if the Properties.Columns.Length > 0

    this won’t solve everything but as I understand it right now, will prevent that exception and your code will keep running (but eventually not really doing exactly what you expect from it if the error is somewhere else in the fact that list should not be empty).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Error is: Index was out of range. Must be non-negative and less than the
I am getting Index was out of range. Must be non-negative and less than
I am getting an error: Index was out of range. Must be non-negative and
I receive the exception Index was out of range. Must be non-negative and less
Why do i get this error(Index was out of range. Must be non-negative and
My soluton here: http://www.mediafire.com/?rzrhvc71musz793 I get error Additional information: Index was out of range.
playerProfileID = (int)transfersDGV.SelectedRows[transfersDGV.CurrentRow.Index] .Cells[0].Value; I get an error saying: Index was out of range.
Please, what is wrong with this: Form2_Closing: Form1.DataGridView1.Rows[0].Cells[1].Value = 323; Error: Index was out
At runtime the program says an index is out of range, but I don't
When I run php-closure i get a PHP error Undefined index: HTTP_IF_NONE_MATCH in <b>/php-closure.php</b>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.