I am writing code to automate the code of PLSQL basic structure. So i have a list which holds the parameters, example as below,
pv_student_name IN VARCHAR2
pn_number OUT NUMBER
So the parameters must be properly aligned as above, So I have written a procedure (method) in c#
which takes plain input and align the parameters and returns a list with properly aligned parameters.
But When I print in the Console using System.Console.WriteLine
then the parameters are aligned properly But when I see the parameters in a List Box
the parameters are not aligned properly , though the spaces are added.
Below is the alignment code.
//Alignment of parameters logic
private List<string> alignParameters(List<string> nonAligned_parameters){
List<string> alignedParamtersList = new List<string>();
List<string> parameterList = new List<string>();
List<string> inOutList = new List<string>();
List<string> dataTypeList = new List<string>();
foreach (string parameter in nonAligned_parameters)
{
string[] param = parameter.Split(' ');
int count = 1;
foreach (string word in param)
{
if (count == 1)
{
parameterList.Add(word.Trim());
}
else if (count == 2)
{
inOutList.Add(word.Trim());
}
else if (count == 3) {
dataTypeList.Add(word.Trim());
}
count++;
}
}
// find the longest string in the list
int maxLength = parameterList.Max(x => x.Length);
//aligning the parameters
int numberOfElements= parameterList.Count();
for (int i = 0; i < numberOfElements; i++)
{
string param = parameterList[i].ToString().Trim();
string inOut = inOutList[i].ToString().Trim();
string dataType = dataTypeList[i].ToString().Trim();
int requiredSpace = maxLength - param.Length + 1;
string spaces = new string(' ', requiredSpace);
string spc = "";
if ("OUT".Equals(inOut)) {
spc = " ";
}
else if ("IN".Equals(inOut)) {
spc = " ";
}
string alignedParameter = param +
spaces +
inOut +
spc +
dataType;
// adding aligned parameters in aligned parameter list to be returned
alignedParamtersList.Add(alignedParameter);
}
return alignedParamtersList;
}
Below is the procedure where it is called, when we add a new parameter then the parameter is added, aligned and then populated back in the ListBox
private void button_AddParameter_Click(object sender, EventArgs e)
{
string error = "N";
//validation code here
if ("N".Equals(error)) {
parameterName = label_paramPrefix.Text +
textBox_parameterName.Text +" "+
combo_InOut.SelectedItem.ToString()+" "+
combo_DataType.SelectedItem.ToString();
}
parameterList.Add(parameterName);
// Align the parameters
parameterListAligned = alignParameters(parameterList);
// populating parameter list in GUI with fresh aligned parameters
listBox_parameter.Items.Clear();
foreach (string parameters in parameterListAligned)
{
listBox_parameter.Items.Add(parameters);
System.Console.WriteLine("param" + parameters);
}
}
So the problem is that even if the Console outputs the parameters aligned properly, the ListBox
doesn't.
Can you guys please help me with this, I need those parameters to appear aligned in the ListBox
as well.
Screen shot of the application where we can see the parameters not aligned in the ListBox
is attached. and console output screenshot is also attached below that.