private void btnOK_Click(object sender, EventArgs e)
        {
            Sql.ExtendedEvents.Session s = (Sql.ExtendedEvents.Session)lbSessions.SelectedItem;

            if (s.Started)
            {
                this.DialogResult = DialogResult.OK;
                session           = s;
                this.Close();
            }
            else
            {
                MessageBox.Show("Selected Extended Events Session is stopped.",
                                "XEvents", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void lbSessions_DrawItem(object sender, DrawItemEventArgs e)
        {
            //Sql.ExtendedEvents.Session s = (Sql.ExtendedEvents.Session)sender;

            Sql.ExtendedEvents.Session s = (Sql.ExtendedEvents.Session)lbSessions.Items[e.Index];

            e.DrawBackground();
            Graphics g = e.Graphics;

            if (!s.Started)
            {
                g.FillRectangle(new SolidBrush(Color.LightGray), e.Bounds);
            }

            // Listbox item text.
            g.DrawString(s.Name, lbSessions.Font, Brushes.Black, lbSessions.GetItemRectangle(e.Index).Location);

            e.DrawFocusRectangle();
        }
Example #3
0
        private void btnPickSession_Click(object sender, EventArgs e)
        {
            try
            {
                if (scd.ConnectionStringBuilder == null || string.IsNullOrEmpty(scd.ConnectionStringBuilder.ConnectionString))
                {
                    MessageBox.Show("You must connect to an instance of SQL Server", "Not Connected",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    connectToSQLToolStripMenuItem_Click(sender, e);
                }
                else
                {
                    DialogResult        dlg = new DialogResult();
                    SessionPickerDialog spd = new SessionPickerDialog(scd.ConnectionStringBuilder);

                    dlg = spd.ShowDialog();

                    if (dlg == DialogResult.OK)
                    {
                        txtXEventSession.Text = spd.SelectedSession.Name;
                        session = spd.SelectedSession;

                        //Add event names to the list box.
                        clbEvents.Items.Clear();
                        clbEvents.Items.AddRange(session.SelectedEvents.ToArray());

                        //All event names checked by default.
                        for (int i = 0; i < clbEvents.Items.Count; i++)
                        {
                            clbEvents.SetItemChecked(i, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }