This is a migrated thread and some comments may be shown as answers.

how to use dynamic datasource

6 Answers 256 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Bala
Top achievements
Rank 1
Bala asked on 04 May 2012, 07:04 PM
Hello,

I just started to use WinForms 2011 Q3 SP1. 
and can't get multicolumncombobox work properly.  Please help.

When users type in a letter in multicolumncombobox, I will send a search to web service fetching a list of symbols (together with other info of the symbol) that begin with the typed letter. say, if a user types "A",  the search will return symbols begins with "A", like A, A1, AB, ABC, etc. Each symbol has 3 columns,  name, description, group. 
I subscribe textchanged event, however, it seems it does not work well. 
When I type in one letter, it is OK, when I type in two letters say "A", then "B",   after I type in "A", cursor goes back to the beginning of text, so it displays "BA". 
Also I have to unsubscribe textchanged event and re-sub in the handler, otherwise, the text changed event is triggered endlessly.
I wonder is there a better way? 

Thanks 

        private void radMultiColumnComboBox1_TextChanged(object sender, EventArgs e)
        {
            var searchText = radMultiColumnComboBox1.Text.Trim();
            var url = "https://mysearchURL?substring=" + searchText;
            url = SecurityElement.Escape(url);
            var request = ServiceBase.GetHttpWebRequestWithHeaderProxy(url, basicAuthorizationEncode64);
            var response = request.GetResponse();
            Stream streamResponse = response.GetResponseStream();
            if (streamResponse != null)
            {
                var streamRead = new StreamReader(streamResponse);
                String strData = streamRead.ReadToEnd();
                var resultlist = Deserialise(strData);
                radMultiColumnComboBox1.TextChanged -= radMultiColumnComboBox1_TextChanged;
                radMultiColumnComboBox1.DataSource = resultlist;               
                radMultiColumnComboBox1.MultiColumnComboBoxElement.ShowPopup();
                radMultiColumnComboBox1.Text = searchText;
                radMultiColumnComboBox1.TextChanged += radMultiColumnComboBox1_TextChanged;
            }
        }

6 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 08 May 2012, 03:23 PM
Hi Bala,

Thank you for contacting us.

This functionality is not available out of the box in RadMultiColumnComboBox, so you will have to implement it. However, this is an interesting feature and we will consider its implementation in a future version. Here is the modified version of your code, which demonstrates how to implement this scenario:
RadMultiColumnComboBox box = new RadMultiColumnComboBox();
box.DisplayMember = "Name";
box.ValueMember = "ID";
box.Location = new Point(50, 50);
box.Size = new Size(200, 20);           
box.TextChanged += new EventHandler(box_TextChanged);
box.DataSource = setDataSource("");
this.Controls.Add(box);
box.SelectedValue = null;
 
bool textChanged = false;
 
void box_TextChanged(object sender, EventArgs e)
{
    if (textChanged)
    {
        return;
    }
    textChanged = true;
 
    RadMultiColumnComboBox box = (RadMultiColumnComboBox)sender;
    string searchText = box.Text.Trim();
    box.DataSource = setDataSource(searchText);           
    box.Text = searchText;
    box.MultiColumnComboBoxElement.ShowPopup();
    TextBox textbox = (TextBox)box.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.HostedControl;
    textbox.SelectionLength = 0;
    textbox.SelectionStart = textbox.Text.Length;
 
    textChanged = false;
}

I hope it helps. If you have any other questions, do not hesitate to contact me.

Regards,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Bala
Top achievements
Rank 1
answered on 08 May 2012, 11:00 PM
Thank you very much. It helps. Now I have another question, how to control size of gridview. say when there are too many items in drop down view, display scrollbar,  when there are too few, display all.  I tried the following. however, it does not work.  thanks

 

        private void initMultiColumnComboBox()
        {              
            radMultiColumnComboBox1.AutoSizeDropDownToBestFit = true;          

            var multiColumnComboElement = radMultiColumnComboBox1.MultiColumnComboBoxElement;
            multiColumnComboElement.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
            multiColumnComboElement.DropDownMinSize = new Size(420, 300);

            multiColumnComboElement.EditorControl.MasterTemplate.AutoGenerateColumns = false;
           
            var column = new GridViewTextBoxColumn("mimsym");
            column.HeaderText = "MIMSym";
            multiColumnComboElement.Columns.Add(column);

            column = new GridViewTextBoxColumn("mimsymQuoted");
            column.HeaderText = "";
            column.IsVisible = false;
            multiColumnComboElement.Columns.Add(column);           

            column = new GridViewTextBoxColumn("desc");
            column.HeaderText = "Description";
            multiColumnComboElement.Columns.Add(column);
           
            column = new GridViewTextBoxColumn("exchange");
            column.HeaderText = "Exchange";
            multiColumnComboElement.Columns.Add(column);

            column = new GridViewTextBoxColumn("instrument");
            column.HeaderText = "Instrument";
            multiColumnComboElement.Columns.Add(column);

            column = new GridViewTextBoxColumn("product");
            column.HeaderText = "Product";
            multiColumnComboElement.Columns.Add(column);

            radMultiColumnComboBox1.AutoFilter = true;
            var descriptor = new FilterDescriptor(radMultiColumnComboBox1.DisplayMember, FilterOperator.StartsWith, string.Empty);
            radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(descriptor);
            radMultiColumnComboBox1.DropDownStyle = RadDropDownStyle.DropDown;

            radMultiColumnComboBox1.DisplayMember = "mimsym";
            radMultiColumnComboBox1.ValueMember = "mimsymQuoted";
        }

 

 

 

0
Jack
Telerik team
answered on 11 May 2012, 04:13 PM
Hello Bala,

You should set the AutoSizeDropDownHeight property in order to resize the RadMultiColumnComboBox popup based on its content. However, in this case the popup will resize only when opening and not when changing its value. To overcome this issue you need a trick. You should post an event to RadMultiColumnComboBox which tells that the filtering was changed. Consider the sample below:
RadMultiColumnComboBox box = new RadMultiColumnComboBox();
box.AutoSizeDropDownHeight = true;
box.AutoFilter = true;
box.DisplayMember = "Name";
box.ValueMember = "ID";
box.Location = new Point(50, 50);
box.Size = new Size(200, 20);          
box.TextChanged += new EventHandler(box_TextChanged);
box.DataSource = setDataSource("");
this.Controls.Add(box);
box.SelectedValue = null;           
 
bool textChanged = false;
 
void box_TextChanged(object sender, EventArgs e)
{
    if (textChanged)
    {
        return;
    }
    textChanged = true;
 
    RadMultiColumnComboBox box = (RadMultiColumnComboBox)sender;
    string searchText = box.Text.Trim();
    box.DataSource = setDataSource(searchText);
    box.Text = searchText;
    box.MultiColumnComboBoxElement.ShowPopup();
             
    GridViewEventInfo eventInfo = new GridViewEventInfo(KnownEvents.ViewChanged, GridEventType.UI, GridEventDispatchMode.Send);
    DataViewChangedEventArgs args = new DataViewChangedEventArgs(ViewChangedAction.FilteringChanged);
    GridViewEvent gridEvent = new GridViewEvent(box.EditorControl.MasterTemplate, this, new object[] { args }, eventInfo);           
    box.EditorControl.MasterTemplate.SynchronizationService.DispatchEvent(gridEvent);
 
    TextBox textbox = (TextBox)box.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.HostedControl;
    textbox.SelectionLength = 0;
    textbox.SelectionStart = textbox.Text.Length;
 
    textChanged = false;
}

I hope this helps. If you need further assistance, do not hesitate to contact me.
 
Regards,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Xavier Soares
Top achievements
Rank 2
answered on 13 Feb 2013, 06:11 PM
Hello,

I've tried to use the code that You kindly posted here and I have a question to make/issue to report.

The code works well if I don't use a blank char (space key) in the text to search for. I've removed the TRIM function from the following code to work around :

string searchText = box.Text.Trim();


Best regards.
Luís Maurício
0
Jack
Telerik team
answered on 14 Feb 2013, 03:14 PM
Hi Luis,

Is the work around sufficient in your scenario? If you need further assistance, please do not hesitate to contact us.
 
Kind regards,
Jack
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Xavier Soares
Top achievements
Rank 2
answered on 14 Feb 2013, 04:11 PM
Hi Jack!

Sorry for the confusing post!

Yes, the work around fix it!

Best regards,
Luís Maurício
Tags
MultiColumn ComboBox
Asked by
Bala
Top achievements
Rank 1
Answers by
Jack
Telerik team
Bala
Top achievements
Rank 1
Xavier Soares
Top achievements
Rank 2
Share this question
or