Getting Columns that contains a certain string

2 posts, 0 answers
  1. Empanada
    Empanada avatar
    6 posts
    Member since:
    Sep 2011

    Posted 11 Jan 2012 Link to this post

    Hey :)

    I made a radgridview  that displays too multiple columns

    And within this radgridview  , it has a column FirstNAme, MiddleName, LastName,  QuizAverage, Quiz1, Quiz2, Quiz3 etc

    How can I get the columns that contains the string "Quiz" such as QuizAverage, Quiz1, Quiz2, Quiz3 etc.. without specifying their indexes?
    Just by mere Identifying wheter a ceratin column name contains "Quiz"

    Thanks for help in this regard :)

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Jan 2012 Link to this post

    Hi Empanada,

    You can use this method to support this functionality:
    private GridViewColumn[] FindColumns(string containsText)
    {
        List<GridViewColumn> columns = new List<GridViewColumn>();
        foreach (var item in radGridView1.Columns)
        {
            if (item.Name.Contains(containsText))
            {
                columns.Add(item);
            }
        }
     
        return columns.ToArray();
    }

    I hope this helps. Let me know if you need further assistance.

    Kind regards,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top