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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Ole Db;
using SAS.EG.AddIns;
namespace Sausag
{
/// <summary>
/// Summary description for CharacterizeDat aForm.
/// </summary>
public class SausagForm : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r 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>
/// ISASTaskConsume r, our hook to the host application for services
/// </summary>
public ISASTaskConsume r Consumer
{
set
{
consumer = value;
}
}
private ISASTaskConsume r 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.Dat aTable dataTable1;
private System.Data.Dat aColumn dataColumn1;
private System.Data.Dat aColumn dataColumn2;
private System.Data.Dat aSet dsVMember;
private System.Windows. Forms.Label lblData;
public SausagForm()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
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.Dat aSet();
this.dataTable1 = new System.Data.Dat aTable();
this.dataColumn 1 = new System.Data.Dat aColumn();
this.dataColumn 2 = new System.Data.Dat aColumn();
((System.Compon entModel.ISuppo rtInitialize)(t his.dsVMember)) .BeginInit();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataTable1) ).BeginInit();
this.SuspendLay out();
//
// lblLib
//
this.lblLib.Fla tStyle = System.Windows. Forms.FlatStyle .System;
this.lblLib.Loc ation = new System.Drawing. Point(5, 44);
this.lblLib.Nam e = "lblLib";
this.lblLib.Siz e = new System.Drawing. Size(166, 23);
this.lblLib.Tab Index = 2;
this.lblLib.Tex t = "Select a library to analyze:";
//
// btnOK
//
this.btnOK.Anch or =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Right)));
this.btnOK.Dial ogResult = System.Windows. Forms.DialogRes ult.OK;
this.btnOK.Flat Style = System.Windows. Forms.FlatStyle .System;
this.btnOK.Loca tion = new System.Drawing. Point(225, 311);
this.btnOK.Name = "btnOK";
this.btnOK.TabI ndex = 11;
this.btnOK.Text = "OK";
//
// btnCancel
//
this.btnCancel. Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Right)));
this.btnCancel. DialogResult = System.Windows. Forms.DialogRes ult.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.Loc ation = new System.Drawing. Point(5, 12);
this.label1.Nam e = "label1";
this.label1.Siz e = new System.Drawing. Size(167, 23);
this.label1.Tab Index = 0;
this.label1.Tex t = "Select a SAS server to use:";
//
// cmbServers
//
this.cmbServers .Anchor =
((System.Window s.Forms.AnchorS tyles)(((System .Windows.Forms. AnchorStyles.To p
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right)));
this.cmbServers .DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st;
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 .SelectedIndexC hanged += new
System.EventHan dler(this.cmbSe rvers_SelectedI ndexChanged);
//
// cmbLibs
//
this.cmbLibs.An chor =
((System.Window s.Forms.AnchorS tyles)(((System .Windows.Forms. AnchorStyles.To p
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right)));
this.cmbLibs.Dr opDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st;
this.cmbLibs.Lo cation = new System.Drawing. Point(177, 42);
this.cmbLibs.Na me = "cmbLibs";
this.cmbLibs.Si ze = new System.Drawing. Size(201, 21);
this.cmbLibs.Ta bIndex = 2;
this.cmbLibs.Se lectedIndexChan ged += new
System.EventHan dler(this.cmbLi bs_SelectedInde xChanged);
//
// lblData
//
this.lblData.Lo cation = new System.Drawing. Point(5, 82);
this.lblData.Na me = "lblData";
this.lblData.Si ze = new System.Drawing. Size(172, 16);
this.lblData.Ta bIndex = 5;
this.lblData.Te xt = "Selected data:";
//
// label3
//
this.label3.Anc hor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.label3.Loc ation = new System.Drawing. Point(5, 213);
this.label3.Nam e = "label3";
this.label3.Siz e = new System.Drawing. Size(221, 16);
this.label3.Tab Index = 9;
this.label3.Tex t = "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.EventHan dler(this.txtCa tobs_TextChange d);
//
// cmbMembers
//
this.cmbMembers .DataSource = this.dsVMember;
this.cmbMembers .DisplayMember = "vmember.memnam e";
this.cmbMembers .DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st;
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 .SelectedIndexC hanged += new
System.EventHan dler(this.cmbMe mbers_SelectedI ndexChanged);
//
// dsVMember
//
this.dsVMember. DataSetName = "data";
this.dsVMember. Locale = new System.Globaliz ation.CultureIn fo("en-AU");
this.dsVMember. Tables.AddRange (new System.Data.Dat aTable[] {
this.dataTable1 });
//
// dataTable1
//
this.dataTable1 .Columns.AddRan ge(new System.Data.Dat aColumn[] {
this.dataColumn 1,
this.dataColumn 2});
this.dataTable1 .TableName = "vmember";
//
// dataColumn1
//
this.dataColumn 1.ColumnName = "memname";
//
// dataColumn2
//
this.dataColumn 2.ColumnName = "memtype";
//
// SausagForm
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(395, 341);
this.Controls.A dd(this.cmbMemb ers);
this.Controls.A dd(this.txtCato bs);
this.Controls.A dd(this.label3) ;
this.Controls.A dd(this.lblData );
this.Controls.A dd(this.cmbLibs );
this.Controls.A dd(this.cmbServ ers);
this.Controls.A dd(this.label1) ;
this.Controls.A dd(this.btnCanc el);
this.Controls.A dd(this.btnOK);
this.Controls.A dd(this.lblLib) ;
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.MinimumSiz e = new System.Drawing. Size(403, 368);
this.Name = "SausagForm ";
this.StartPosit ion = System.Windows. Forms.FormStart Position.Center Parent;
this.Text = "Characteri ze Data";
this.Load += new System.EventHan dler(this.Chara cterizeDataForm _Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.dsVMember)) .EndInit();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataTable1) ).EndInit();
this.ResumeLayo ut(false);
}
#endregion
private void CharacterizeDat aForm_Load(obje ct sender, System.EventArg s e)
{
if (consumer == null)
throw new System.Exceptio n("Must set ISASTaskConsume r as Consumer
property!");
// get the list of available servers from the application
string[] servers;
consumer.Server s(out servers);
if (servers.Length == 0)
throw new System.Exceptio n("No servers are available!");
// populate the servers combobox
cmbServers.Item s.AddRange(serv ers);
if (consumer.Assig nedServer.Lengt h>0)
cmbServers.Sele ctedItem = consumer.Assign edServer;
currServer = cmbServers.Sele ctedItem.ToStri ng();
PopulateLibrary List();
txtCatobs.Text = catobs;
// UpdateControls( );
}
private void PopulateLibrary List()
{
Cursor c = Cursor.Current;
Cursor.Current = Cursors.WaitCur sor;
cmbLibs.Items.C lear();
string[] libs;
consumer.Librar ies(cmbServers. SelectedItem.To String(), out libs);
if (libs.Length == 0)
{
Cursor.Current = c;
throw new System.Exceptio n("No libraries are available!");
}
cmbLibs.Items.A ddRange(libs);
if (cmbLibs.Items. Contains(librar y))
cmbLibs.Selecte dItem = library;
else
cmbLibs.Selecte dIndex = 0;
Cursor.Current = c;
}
// uses the Workspace property of the ISASTaskConsume r
// and the SAS IOM OLEDB Provider to connect to
// the SAS session and query for additional information
// about the SAS data
private void PopulateDataset List(string libname)
{
string server = "";
SAS.Workspace ws = null;
try
{
server = consumer.Assign edServer;
ws = consumer.Worksp ace(server) as SAS.Workspace;
}
catch (Exception ex)
{
throw new System.Exceptio n("ISASTaskCons umer.Workspace is not usable!",ex);
}
if (server.Length> 0 && ws!=null)
{
ADODB.Recordset adorecordset = new ADODB.Recordset Class();
ADODB.Connectio n adoconnect = new ADODB.Connectio nClass();
try
{
adoconnect.Open ("Provider=sas. iomprovider.1; SAS Workspace ID=" +
ws.UniqueIdenti fier, "", "", 0);
string selectclause = "select memname, memtype from sashelp.vmember where
libname='" + libname + " ' and memtype = 'DATA'";
adorecordset.Op en( selectclause, adoconnect,
ADODB.CursorTyp eEnum.adOpenFor wardOnly, ADODB.LockTypeE num.adLockReadO nly,
(int) ADODB.CommandTy peEnum.adCmdTex t);
OleDbDataAdapte r da = new OleDbDataAdapte r();
da.Fill(dsVMemb er, adorecordset, "vmember");
}
catch
{
}
finally
{
adoconnect.Clos e();
}
}
}
private void cmbServers_Sele ctedIndexChange d(object sender,
System.EventArg s e)
{
try
{
PopulateLibrary List();
currServer = cmbServers.Sele ctedItem.ToStri ng();
}
catch
{
MessageBox.Show (string.Format( "There was an error trying to connect to
\"{0}\".", cmbServers.Sele ctedItem),"Conn ection error");
cmbServers.Sele ctedItem = currServer;
}
}
private void cmbLibs_Selecte dIndexChanged(o bject sender, System.EventArg s e)
{
try
{
library = cmbLibs.Selecte dItem.ToString( );
PopulateDataset List(library);
}
catch
{
MessageBox.Show (string.Format( "There was an error trying to access\"{0}\"." ,
cmbLibs.Selecte dItem),"Connect ion error");
cmbLibs.Selecte dItem = library;
}
}
private void OnCurrentDataCe llChanged(objec t sender, System.EventArg s e)
{
try
{
DataSet ds = cmbMembers.Data Source as DataSet;
members = cmbServers.Sele ctedIndex.ToStr ing();
}
catch
{
}
}
private void txtCatobs_TextC hanged(object sender, System.EventArg s e)
{
try
{
// catobs = Convert.ToInt32 (txtCatobs.Text );
catobs = Convert.ToStrin g(txtCatobs.Tex t);
}
catch
{
}
}
private void cmbMembers_Sele ctedIndexChange d(object sender,
System.EventArg s e)
{
members=((DataR owView)cmbMembe rs.SelectedItem ).Row.ItemArray[0].ToString();
}
}
}
//