"autogenerate" columns in multi column combobox

6 posts, 0 answers
  1. Christian
    Christian avatar
    3 posts
    Member since:
    Oct 2010

    Posted 05 Oct 2010 Link to this post

    I'm using a autocompleting and multicolumns radcombo box to produce an application.

    Up to now I've hard coded the itemtemplate in the aspx page bt now I'm trying to roll it out a bit more dynamically.

    Part of the application allows users to choose which database fields to include in the query so I won't know what to add to the <itemtemplate> until run time.

    What is the best way to dynamically "autogenerate" the columns in the multicolumn combo??
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 08 Oct 2010 Link to this post

    Hi Christian,

    Please take a look at the "Dynamic Multi-Column Template" Code Library.

    Greetings,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Christian
    Christian avatar
    3 posts
    Member since:
    Oct 2010

    Posted 11 Oct 2010 Link to this post

    thank you , its  step in the right direction but doesn't entirely solve my problem....

    I have an application which allows users to choose which columns are included in a SQL statement, so the resulting multicolumn could have 3 or 13 columns in it, with no set column name.  The code you kindly suggested requires that the columns be "pre-built" in the "InstatiateIn" function.
  4. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 14 Oct 2010 Link to this post

    Hi Christian,

    The scenario that you are trying to implement is quite unusual – I started researching the issue but this will take some more time. I will contact you when I find something of interest.

    Best wishes,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Christian
    Christian avatar
    3 posts
    Member since:
    Oct 2010

    Posted 15 Oct 2010 Link to this post

    Well, I've achieved some success.  I am now able to create a dynamic multicolumn dropdown with dynamic column count.

    in the main asp.cs file:

    DataTable dt = GetData(e.Text);
    //use my SQL to create a datatable
    int colCount = dt.Columns.Count;
    //count how many columns are in the table and pass this out to the templates to create the correct number of coulmns
    RadComboBoxProduct.HeaderTemplate = new MultiColumnHeaderTemplate(colCount);
    RadComboBoxProduct.ItemTemplate = new MultiColumnItemTemplate(colCount);
     
    RadComboBoxProduct.DataSource = dt;
    RadComboBoxProduct.DataTextField = "idCode";
    //I've slightly cheated here because the first column in my SQL will ALWAYS be this column entitled idCode
    RadComboBoxProduct.DataBind();







    In the itemTemplate.cs file:
        
    public int colCount;
        public int counter = 0;
        public MultiColumnItemTemplate(int i)
        {
            colCount = i;
        }
        public void InstantiateIn(Control container)
        {
            decimal split = 100 / colCount;
            int splitInt = Convert.ToInt32(Math.Round(split));
    //because individual radcomboboxitems are dealt with as seperate tables, it doesn't always keep the columns straight
    //the code gets around this by dividing the space equally between the number of columns.  turning on wrap makes this work. It does however break if too many columns are displayed, causing the columns to be too thin for the longest string in the columns
            Table tb;
            TableRow tr;
            tb = new Table();
            tb.Width = Unit.Percentage(100);
            tr = new TableRow();
            for (int i = 0; i < colCount; i++)
            {
                TableCell tc;
                tc = new TableCell();
                tc.Width = Unit.Percentage(splitInt);
                tc.DataBinding += new EventHandler(tdCell_DataBinding);
                tc.Wrap = true;
                tr.Cells.Add(tc);
            }
            tb.Rows.Add(tr);
            container.Controls.Add(tb);
        }





    All of the columns are given the same datbinding function:
    void tdCell_DataBinding(object sender, EventArgs e)
        {
            TableCell tc = (TableCell)sender;
            RadComboBoxItem item = (RadComboBoxItem)tc.BindingContainer;
            DataRowView row = (DataRowView)item.DataItem;
            tc.Text = row[counter].ToString();
    //using previous code to determine how many coumns my sql requires
    //this loops through the rows being passed to put the contents of each row
            if (counter < colCount-1)
            {
                counter ++;
            }
            else
            {
                counter=0;
            }
        }



    so right now this is mostly working except:

    I currently can't get the headertemplate to display column names

    bit of a hack on the table columns, I think getting the headertemplate working would sort this and create proper columns


    its still a work in progress!! thanks for your assistance thus far.

    CB
  6. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 26 Oct 2010 Link to this post

    Hi Christian,

    As I understand, you have created two custom templates: MulticolumnItemTemplate and MulticolumnHeaderTemplate.
    However at the code snippets provided I can see only the code of MulticolumnItemTemplate.
    Could you please paste here the implementation of MultiColumnHeaderTemplate?
    Thank you in advance.

    All the best,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top