Skip to content

Adding combo box to MS Report Viewer ToolStrip

Matthew Coffin

Asked Feb 3, 2012, 11:59 AM EST1 answer
Share
LinkedInX
Hi - I am trying to use the MS Report viewer in a project. I have been able to add a combobox to the toolstrip of the reprt viewer, and I can detect the selectedindexchange event, but I do not understand how to get the indexvalue of the item selected in this combo box

Private

Dim ts() As Control = Me.ReportViewer1.Controls.Find("toolStrip1", True)

If ts IsNot Nothing ThenDim tsItem As ToolStrip = DirectCast(ts(0), ToolStrip)
Dim sep As New ToolStripSeparator
Dim Lab As New ToolStripLabel
Dim tscbo As New ToolStripComboBox
Dim tboxcbo1 As New ArrayList
tboxcbo1.Add(New mmtypevalues(0, "Todos"))
tboxcbo1.Add(New mmtypevalues(1, "Not Used"))
tboxcbo1.Add(New mmtypevalues(2, "Mandatory"))
tboxcbo1.Add(New mmtypevalues(3, "Supplied"))
tboxcbo1.Add(New mmtypevalues(4, "Optional"))
sep.Name = "sep1"
sep.Alignment = ToolStripItemAlignment.Left
Lab.Name = "Lab01"
Lab.Alignment = ToolStripItemAlignment.Left
tscbo.Alignment = ToolStripItemAlignment.Left

With tscbo.ComboBox
.Name = "pmtsComboBox1"
.BackColor = Color.Green
.ForeColor = Color.White
.BindingContext = Me.BindingContext
ValueMember = "Value"
.DisplayMember = "Display"
.DataSource = tboxcbo1
End With

tsItem.Items.Add(sep)
tsItem.Items.Add(Lab)
tsItem.Items.Add(tscbo)
AddHandler tscbo.ComboBox.SelectedIndexChanged, AddressOf pmtsComboBox1SIC

End If

The handler detects the selectedindexchange, but I do'nt know how to access the selectedindex of
the toolstripcombobox created

Can anyone help





Sub AddReportViewerButton()

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    HI Matthew

    c# example

    1-add combobox to toolstrip

              ToolStripComboBox MyCombo= new ToolStripComboBox(); 
          
                foreach (Control ctrl in crystalReportViewer1.Controls)
                {
                 
                    if (ctrl is System.Windows.Forms.ToolStrip)
                    {
                        //ToolStripComboBox combobox = new ToolStripComboBox();
                        combobox.Items.Add("ds");
                        combobox.Items.Add("fd");  
                        ((ToolStrip)ctrl).Items.Add(combobox);

                        combobox.ComboBox.SelectedIndexChanged += MyCombo_SelectedIndexChanged;  
                    }
                }

    2-access toolstripcombobox SelectedIndexChanged  event

            private void MyCombo_SelectedIndexChanged(object sender, EventArgs e)
            {
                string s = MyCombo.SelectedItem.ToString();

            }


    regards

    Anas
         
    0