This is a repost of an item that I still cannot resolve.
I have 3 combo boxes. The first leads to the second to the third.
When I have selected a value in the second box, the third box shows the
available information based on the second combo box selection. But if I
change my mind and select a different item in the second box, after the
third box has been populated, the third box still retains the information
that was previously selected.
I need to make the third box capable of being refreshed based on a change of
mind from the second. I was told by a previous response that there is
probably an unreported exception, but I am unable to find this - and i a
realy struggling here.
Any assistance kindly appreciated.
//Code//
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using SAS.EG.AddIns;
namespace Sausag
{
/// <summary>
/// Summary description for CharacterizeDataForm.
/// </summary>
public class SausagForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label lblLib;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cmbServers;
private System.Windows.Forms.ComboBox cmbLibs;
#region Properties for this add-in task
/// <summary>
/// ISASTaskConsumer, our hook to the host application for services
/// </summary>
public ISASTaskConsumer Consumer
{
set
{
consumer = value;
}
}
private ISASTaskConsumer consumer = null;
public string Library
{
set
{
library = value;
}
get
{
return library;
}
}
private string library;
public bool IncludeCharts
{
set
{
bCharts = value;
}
get
{
return bCharts;
}
}
private bool bCharts = false;
public bool AllMembers
{
set
{
bAllData = value;
}
get
{
return bAllData;
}
}
private bool bAllData = false;
public string Members
{
set
{
members = value;
}
get
{
return members;
}
}
private string members;
public string Catobs
{
set
{
catobs = value;
}
get
{
return catobs;
}
}
private string catobs = "10";
#endregion
private string currServer = "";
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtCatobs;
private System.Windows.Forms.ComboBox cmbMembers;
private System.Data.DataTable dataTable1;
private System.Data.DataColumn dataColumn1;
private System.Data.DataColumn dataColumn2;
private System.Data.DataSet dsVMember;
private System.Windows.Forms.Label lblData;
public SausagForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblLib = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.cmbServers = new System.Windows.Forms.ComboBox();
this.cmbLibs = new System.Windows.Forms.ComboBox();
this.lblData = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtCatobs = new System.Windows.Forms.TextBox();
this.cmbMembers = new System.Windows.Forms.ComboBox();
this.dsVMember = new System.Data.DataSet();
this.dataTable1 = new System.Data.DataTable();
this.dataColumn1 = new System.Data.DataColumn();
this.dataColumn2 = new System.Data.DataColumn();
((System.ComponentModel.ISupportInitialize)(this.d sVMember)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.d ataTable1)).BeginInit();
this.SuspendLayout();
//
// lblLib
//
this.lblLib.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblLib.Location = new System.Drawing.Point(5, 44);
this.lblLib.Name = "lblLib";
this.lblLib.Size = new System.Drawing.Size(166, 23);
this.lblLib.TabIndex = 2;
this.lblLib.Text = "Select a library to analyze:";
//
// btnOK
//
this.btnOK.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windo ws.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnOK.Location = new System.Drawing.Point(225, 311);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 11;
this.btnOK.Text = "OK";
//
// btnCancel
//
this.btnCancel.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windo ws.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnCancel.Location = new System.Drawing.Point(310, 311);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 12;
this.btnCancel.Text = "Cancel";
//
// label1
//
this.label1.Location = new System.Drawing.Point(5, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(167, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Select a SAS server to use:";
//
// cmbServers
//
this.cmbServers.Anchor =
((System.Windows.Forms.AnchorStyles)(((System.Wind ows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cmbServers.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbServers.Location = new System.Drawing.Point(179, 11);
this.cmbServers.Name = "cmbServers";
this.cmbServers.Size = new System.Drawing.Size(201, 21);
this.cmbServers.TabIndex = 1;
this.cmbServers.SelectedIndexChanged += new
System.EventHandler(this.cmbServers_SelectedIndexC hanged);
//
// cmbLibs
//
this.cmbLibs.Anchor =
((System.Windows.Forms.AnchorStyles)(((System.Wind ows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cmbLibs.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbLibs.Location = new System.Drawing.Point(177, 42);
this.cmbLibs.Name = "cmbLibs";
this.cmbLibs.Size = new System.Drawing.Size(201, 21);
this.cmbLibs.TabIndex = 2;
this.cmbLibs.SelectedIndexChanged += new
System.EventHandler(this.cmbLibs_SelectedIndexChan ged);
//
// lblData
//
this.lblData.Location = new System.Drawing.Point(5, 82);
this.lblData.Name = "lblData";
this.lblData.Size = new System.Drawing.Size(172, 16);
this.lblData.TabIndex = 5;
this.lblData.Text = "Selected data:";
//
// label3
//
this.label3.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windo ws.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left)));
this.label3.Location = new System.Drawing.Point(5, 213);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(221, 16);
this.label3.TabIndex = 9;
this.label3.Text = "Max records to print in each data set:";
//
// txtCatobs
//
this.txtCatobs.Location = new System.Drawing.Point(292, 211);
this.txtCatobs.Name = "txtCatobs";
this.txtCatobs.Size = new System.Drawing.Size(70, 20);
this.txtCatobs.TabIndex = 4;
this.txtCatobs.Text = "10";
this.txtCatobs.TextChanged += new
System.EventHandler(this.txtCatobs_TextChanged);
//
// cmbMembers
//
this.cmbMembers.DataSource = this.dsVMember;
this.cmbMembers.DisplayMember = "vmember.memname";
this.cmbMembers.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbMembers.Location = new System.Drawing.Point(178, 79);
this.cmbMembers.Name = "cmbMembers";
this.cmbMembers.Size = new System.Drawing.Size(201, 21);
this.cmbMembers.TabIndex = 3;
this.cmbMembers.SelectedIndexChanged += new
System.EventHandler(this.cmbMembers_SelectedIndexC hanged);
//
// dsVMember
//
this.dsVMember.DataSetName = "data";
this.dsVMember.Locale = new System.Globalization.CultureInfo("en-AU");
this.dsVMember.Tables.AddRange(new System.Data.DataTable[] {
this.dataTable1});
//
// dataTable1
//
this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {
this.dataColumn1,
this.dataColumn2});
this.dataTable1.TableName = "vmember";
//
// dataColumn1
//
this.dataColumn1.ColumnName = "memname";
//
// dataColumn2
//
this.dataColumn2.ColumnName = "memtype";
//
// SausagForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(395, 341);
this.Controls.Add(this.cmbMembers);
this.Controls.Add(this.txtCatobs);
this.Controls.Add(this.label3);
this.Controls.Add(this.lblData);
this.Controls.Add(this.cmbLibs);
this.Controls.Add(this.cmbServers);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.lblLib);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(403, 368);
this.Name = "SausagForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParen t;
this.Text = "Characterize Data";
this.Load += new System.EventHandler(this.CharacterizeDataForm_Load );
((System.ComponentModel.ISupportInitialize)(this.d sVMember)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.d ataTable1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void CharacterizeDataForm_Load(object sender, System.EventArgs e)
{
if (consumer == null)
throw new System.Exception("Must set ISASTaskConsumer as Consumer
property!");
// get the list of available servers from the application
string[] servers;
consumer.Servers(out servers);
if (servers.Length == 0)
throw new System.Exception("No servers are available!");
// populate the servers combobox
cmbServers.Items.AddRange(servers);
if (consumer.AssignedServer.Length>0)
cmbServers.SelectedItem = consumer.AssignedServer;
currServer = cmbServers.SelectedItem.ToString();
PopulateLibraryList();
txtCatobs.Text = catobs;
// UpdateControls();
}
private void PopulateLibraryList()
{
Cursor c = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
cmbLibs.Items.Clear();
string[] libs;
consumer.Libraries(cmbServers.SelectedItem.ToStrin g(), out libs);
if (libs.Length == 0)
{
Cursor.Current = c;
throw new System.Exception("No libraries are available!");
}
cmbLibs.Items.AddRange(libs);
if (cmbLibs.Items.Contains(library))
cmbLibs.SelectedItem = library;
else
cmbLibs.SelectedIndex = 0;
Cursor.Current = c;
}
// uses the Workspace property of the ISASTaskConsumer
// and the SAS IOM OLEDB Provider to connect to
// the SAS session and query for additional information
// about the SAS data
private void PopulateDatasetList(string libname)
{
string server = "";
SAS.Workspace ws = null;
try
{
server = consumer.AssignedServer;
ws = consumer.Workspace(server) as SAS.Workspace;
}
catch (Exception ex)
{
throw new System.Exception("ISASTaskConsumer.Workspace is not usable!",ex);
}
if (server.Length>0 && ws!=null)
{
ADODB.Recordset adorecordset = new ADODB.RecordsetClass();
ADODB.Connection adoconnect = new ADODB.ConnectionClass();
try
{
adoconnect.Open("Provider=sas.iomprovider.1; SAS Workspace ID=" +
ws.UniqueIdentifier, "", "", 0);
string selectclause = "select memname, memtype from sashelp.vmember where
libname='" + libname + " ' and memtype = 'DATA'";
adorecordset.Open( selectclause, adoconnect,
ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly,
(int) ADODB.CommandTypeEnum.adCmdText);
OleDbDataAdapter da = new OleDbDataAdapter();
da.Fill(dsVMember, adorecordset, "vmember");
}
catch
{
}
finally
{
adoconnect.Close();
}
}
}
private void cmbServers_SelectedIndexChanged(object sender,
System.EventArgs e)
{
try
{
PopulateLibraryList();
currServer = cmbServers.SelectedItem.ToString();
}
catch
{
MessageBox.Show(string.Format("There was an error trying to connect to
\"{0}\".", cmbServers.SelectedItem),"Connection error");
cmbServers.SelectedItem = currServer;
}
}
private void cmbLibs_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
library = cmbLibs.SelectedItem.ToString();
PopulateDatasetList(library);
}
catch
{
MessageBox.Show(string.Format("There was an error trying to access\"{0}\".",
cmbLibs.SelectedItem),"Connection error");
cmbLibs.SelectedItem = library;
}
}
private void OnCurrentDataCellChanged(object sender, System.EventArgs e)
{
try
{
DataSet ds = cmbMembers.DataSource as DataSet;
members = cmbServers.SelectedIndex.ToString();
}
catch
{
}
}
private void txtCatobs_TextChanged(object sender, System.EventArgs e)
{
try
{
// catobs = Convert.ToInt32(txtCatobs.Text);
catobs = Convert.ToString(txtCatobs.Text);
}
catch
{
}
}
private void cmbMembers_SelectedIndexChanged(object sender,
System.EventArgs e)
{
members=((DataRowView)cmbMembers.SelectedItem).Row .ItemArray[0].ToString();
}
}
}
//