How to Load all the crystal report parameter in comboBox using c#
In this article I'm going to how to Load all the crystal report parameter in comboBox using c#? Just drag and drop one button and comboBox from tool box. Within Button click event create object for OpenFileDialog and then show file selection Dialog. After select the crystal report file just load the list of parameter names in comboBox control. comboBox Text field value is Parameter name and then value field is Data type. After select the parameter from comboBox you need to give input to these parameter.
In this article I'm going to how to Load all the crystal report parameter in comboBox using c#? Just drag and drop one button and comboBox from tool box. Within Button click event create object for OpenFileDialog and then show file selection Dialog. After select the crystal report file just load the list of parameter names in comboBox control. comboBox Text field value is Parameter name and then value field is Data type. After select the parameter from comboBox you need to give input to these parameter.
Based on Data type enable disable the control. So I given two more control one for Text box control another one datetime picker control. Based on comboBox value
these two controls are enabled. Herewith i have given full source code kindly check this. These same concept will work in asp.net also so.
private void BBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog OpenFile = new OpenFileDialog();
try
{
OpenFile.FileName = "";
OpenFile.Title = "All files:";
//OpenFile.Filter = "Image files: (*.*)";
DialogResult res = OpenFile.ShowDialog();
if (res == DialogResult.OK)
{
txtPath.Text = OpenFile.InitialDirectory + OpenFile.FileName;
ReportDocument cryRpt;
cryRpt = new ReportDocument();
cryRpt.Load(txtPath.Text);
DataTable dtEmployeeProduction = new DataTable();
dtEmployeeProduction.Columns.Add("TypeID", typeof(string));
dtEmployeeProduction.Columns.Add("TypeName", typeof(string));
foreach (ParameterFieldDefinition pd in cryRpt.DataDefinition.ParameterFields)
{
dRow = dtEmployeeProduction.NewRow();
dRow["TypeID"] = pd.ValueType.ToString();
dRow["TypeName"] = pd.ParameterFieldName.ToString();
dtEmployeeProduction.Rows.InsertAt(dRow, 0);
}
cmbParameter.DataSource = dtEmployeeProduction;
cmbParameter.DisplayMember = "TypeName";
cmbParameter.ValueMember = "TypeID";
cmbParameter.SelectedIndex = 1;
}
}
catch (Exception ex)
{
}
}
private void cmbParameter_SelectedIndexChanged(object sender, EventArgs e)
{
txtStringField.Text = string.Empty;
if (cmbParameter.SelectedValue.ToString() == "StringField")
{
txtStringField.Enabled = true;
txtDateField.Enabled = false;
}
else if (cmbParameter.SelectedValue.ToString() == "DateField")
{
txtDateField.Enabled = true;
txtStringField.Enabled = false;
}
else if (cmbParameter.SelectedValue.ToString() == "DateTimeField")
{
txtDateField.Enabled = true;
txtStringField.Enabled = false;
}
else if (cmbParameter.SelectedValue.ToString() == "NumberField")
{
txtStringField.Enabled = true;
txtDateField.Enabled = false;
}
}