I create a FaceDetectionEvent which is a user control and try to add it in windows form (still in the same project). But it keeps showing this error:
This is the FaceDetectionEvent code:
public partial class FaceDetectionEvent : UserControl
{
private System.Timers.Timer tListener;
private MySQL_DataAccess da = new MySQL_DataAccess();
private int iCurrentStatusIndex_ = 0;
private List<DataRow> lstFaceDetectionEvent = new List<DataRow>(20);
private ImageList cropImageList = new ImageList();
public FaceDetectionEvent()
{
InitializeComponent();
CreateColumns();
GetLastTwentyEvent();
tListener = new System.Timers.Timer(1000);
tListener.Elapsed += new System.Timers.ElapsedEventHandler(tListener_Elapsed);
tListener.Start();
}
public void GetLastTwentyEvent()
{
string strSQL = string.Format("SELECT * FROM av_status_log AS A LEFT JOIN avmediaserver AS B ON A.device_id=B.DeviceId "
+ "LEFT JOIN privilege_device AS C ON A.device_id = C.device_id "
+ "LEFT JOIN privilege_device_group AS D ON C.device_group_id = D.device_group_id "
+ "WHERE event_type_id = 8 ORDER BY A.db_time DESC LIMIT 20");
DataTable dt = da.GetInfoData(strSQL).Tables[0];
if (dt.Rows.Count > 0)
iCurrentStatusIndex_ = Convert.ToInt32(dt.Rows[0]["rowid"]);
foreach (DataRow dr in dt.Rows)
{
lstFaceDetectionEvent.Add(dr);
string strCroppedImage = GetCropImageBase64String(dr["memo"].ToString());
cropImageList.Images.Add(Base64ToImage(strCroppedImage));
}
ShowFDEvent();
}
void tListener_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string strSQL = string.Format("SELECT * FROM av_status_log AS A LEFT JOIN avmediaserver AS B ON A.device_id=B.DeviceId "
+ "LEFT JOIN privilege_device AS C ON A.device_id = C.device_id "
+ "LEFT JOIN privilege_device_group AS D ON C.device_group_id = D.device_group_id "
+ "WHERE A.rowid > {0} AND event_type_id = 8 ORDER BY A.db_time DESC", iCurrentStatusIndex_.ToString());
DataTable dt = da.GetInfoData(strSQL).Tables[0];
if (dt.Rows.Count > 0)
iCurrentStatusIndex_ = Convert.ToInt32(dt.Rows[0]["rowid"]);
if (lstFaceDetectionEvent.Count >= 20)
{
lstFaceDetectionEvent.RemoveRange(0, dt.Rows.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
cropImageList.Images.RemoveAt(i);
}
}
foreach (DataRow dr in dt.Rows)
{
lstFaceDetectionEvent.Add(dr);
string strCroppedImage = GetCropImageBase64String(dr["memo"].ToString());
cropImageList.Images.Add(Base64ToImage(strCroppedImage));
}
ShowFDEvent();
this.Refresh();
}
public string GetCropImageBase64String(string pStrMemo)
{
XElement doc = XElement.Parse(pStrMemo);
string strCropImage = doc.Element("cropImage").Value;
return strCropImage;
}
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
private void CreateColumns()
{
ColumnHeader cropImageHeader = new ColumnHeader();
cropImageHeader.Text = "Crop Image";
cropImageHeader.Width = 150;
FDEventlistView.Columns.Add(cropImageHeader);
ColumnHeader timestampHeader = new ColumnHeader("Event Time");
timestampHeader.Text = "Event Time";
timestampHeader.Width = 150;
FDEventlistView.Columns.Add(timestampHeader);
ColumnHeader deviceNameHeader = new ColumnHeader("Device Name");
deviceNameHeader.Text = "Size";
deviceNameHeader.Width = 80;
FDEventlistView.Columns.Add(deviceNameHeader);
}
private void ShowFDEvent()
{
FDEventlistView.Items.Clear();
FDEventlistView.BeginUpdate();
int i = 0;
foreach (DataRow dr in lstFaceDetectionEvent)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = i;
ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem();
subitem.Text = dr["status_time"].ToString();
item.SubItems.Add(subitem);
subitem = new ListViewItem.ListViewSubItem();
subitem.Text = dr["device_name"].ToString();
item.SubItems.Add(subitem);
FDEventlistView.Items.Add(item);
i++;
}
FDEventlistView.EndUpdate();
}
}
Do you have any idea why?
Code in your UserControl will run at design time as well. A feature that provides the WYSIWIG behavior of a control when you drop it on a form with the designer. But certainly can be troublesome, in this case you do not want to query the dbase, no chance that you'll be able to find the correct connection string when the control is loaded in Visual Studio instead of your program. Simply skipped by using the DesignMode property:
public FaceDetectionEvent()
{
InitializeComponent();
tListener = new System.Timers.Timer(1000);
tListener.Elapsed += new System.Timers.ElapsedEventHandler(tListener_Elapsed);
if (!this.DesignMode) {
CreateColumns();
GetLastTwentyEvent();
tListener.Start();
}
}
You may need to insert the DesignMode test in other places in your code, like Paint and Load event handlers.
Do note how debugging such design-time only exceptions can be difficult, the message box isn't big enough to show you the stack trace. In the really hard cases you may need to debug Visual Studio itself so you can see the exception. Start another instance of VS and use Tools + Attach to Process to attach the debugger to the 1st instance. Debug + Exceptions, tick the Thrown checkbox to automatically break when the exception is thrown.
I don't think the problem is about UserControl. To prove this, create a new user control, this time not programmatically -> Add New and choose UserControl. Delete the FaceDetectionEvent Control from the MainForm for now, then add the newly created UserControl and see if the error shows up again. If it does please share the content of the StackTrace.
I've had this same issue trying to add my user controls to a form by dragging it from the tool box. It may seem obvious, but my issues involved having parameters in the constructor that were intended to be passed at run-time if the control was added programatically...
So this code will cause the error. To avoid it don't have arguments in the constructor.
public ucMyControl(string title)
{
InitializeComponent();
groupBox1.Text = title;
}
Related
public partial class DataGrid_HBD : UserControl
{
public DataGrid_HBD()
{
InitializeComponent();
// 2 Seconds Timer before connecting to the Database.
// This improves UI rendering on button click
DataGrid_Data();
}
/// <summary>
/// Loading Data Grid
/// </summary>
public void DataGrid_Data()
{
// 2 second delay before loading DataGrid
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) };
timer.Start();
timer.Tick += (sender, args) =>
{
timer.Stop();
// Attempt to connect to SQL Server database and populate DataGrid with database tables.
try
{
string connectionString = ("Data Source=\\SQLEXPRESS;Initial Catalog=CustomerRelations;Integrated Security=True;");
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT [hb_Disputes].[DSP_ID], [hb_disputes].[ACCOUNT], [Users].[TX_EMPLOYEE], [hb_CsrNames].[NM_USER], [hb_disputes].[CUST_NAME],[hb_disputes].[PREM_ADDR], [hb_status].[Status], [hb_disputes].[OPENED], [hb_disputes].[DEADLINE], [hb_disputes].[DATERSLVD], [hb_rpttype].[ReportType], [hb_ratetype].[RateType], [hb_Disputes].[FR_DT_FIRSTREV], [hb_Disputes].[FR_TS_LATESTUPD], [hb_Disputes].[COMMENT], [hb_Disputes].[FR_DSP_CLSF], [hb_Disputes].[FR_CUST_CNTCT], [hb_Disputes].[FR_WRK_REQ], [hb_Disputes].[FR_OPN_ERR], [hb_Disputes].[FR_SO_TP], [hb_Disputes].[FR_SO_DTLS], [hb_Disputes].[FR_SO_DT_WNTD], [hb_Disputes].[FR_SO_ISSD_BY], [hb_Disputes].[FR_CMMNT] FROM [hb_disputes]" +
" LEFT JOIN [Users] ON [hb_disputes].[ASSGNTO] = [Users].[KY_USER_ID] LEFT JOIN [hb_CsrNames] ON [hb_disputes].[WFMUSER] = [hb_CsrNames].[KY_USER_ID] LEFT JOIN [hb_status] ON [hb_disputes].[STATUS] = [hb_status].[STSID] LEFT JOIN [hb_rpttype] ON [hb_disputes].[RPTTYPE] = [hb_rpttype].[RPTID] LEFT JOIN [hb_ratetype] ON [hb_disputes].[REV_CLS] = [hb_ratetype].[RTID]", connection);
connection.Open();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
connection.Close();
dtGrid.DataContext = dt;
}
catch
{
MessageBox.Show("Database connection is not available at this time. Please contact your database administrator ");
}
};
}
private void dtGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// User double clicks on DataGrid Row
// Open new Window
// Populate selected textboxes with selected datarow
DataGrid gd = (DataGrid)sender;
DataRowView row_selected = gd.SelectedItem as DataRowView;
var windowToOpen = new Window1();
if(gd !=null )
{
// Textboxes
windowToOpen.txt_RowRecrd.Text = row_selected["DSP_ID"].ToString();
windowToOpen.txt_acctnumber.Text = row_selected["ACCOUNT"].ToString();
windowToOpen.txt_analyst.Text = row_selected["TX_EMPLOYEE"].ToString();
windowToOpen.txt_custname.Text = row_selected["CUST_NAME"].ToString();
windowToOpen.txt_address.Text = row_selected["PREM_ADDR"].ToString();
windowToOpen.txt_Status.Text = row_selected["Status"].ToString();
windowToOpen.txt_opened.Text = row_selected["OPENED"].ToString();
windowToOpen.txt_deadline.Text = row_selected["DEADLINE"].ToString();
windowToOpen.txt_DateResolved.Text = row_selected["DATERSLVD"].ToString();
windowToOpen.txt_revcls.Text = row_selected["RateType"].ToString();
windowToOpen.txt_WFMissuedBy.Text = row_selected["NM_USER"].ToString();
windowToOpen.txt_firstreview.Text = row_selected["FR_DT_FIRSTREV"].ToString();
windowToOpen.txt_Latestupdate.Text = row_selected["FR_TS_LATESTUPD"].ToString();
windowToOpen.txt_reviewNotes.Text = row_selected["FR_CMMNT"].ToString();
windowToOpen.txt_ResolutionNotes.Text = row_selected["COMMENT"].ToString();
// Comboboxes
windowToOpen.cmb_UtilityRptTyp.SelectedItem = row_selected["ReportType"].ToString();
windowToOpen.Show();
}
else
{
return;
}
}
When the user double clicks on a row in the Datagrid, it opens a new window and populates the textboxes with the selected cells. However, it does not work for CombinationBoxes. I attached an image of the new window (Window1) that the information is populating to. The image shows the code behind for the combobox with the populated table from the SQL Server database.
First of all, You must set Datasource of cmb_UtilityRptTyp with a list of available report types like this:
// Define ReportType Class
class ReportType {
public int ID { get; set; }
public string Title { get; set; }
public ReportType(int id, string title)
{
ID = id;
Title = title;
}
}
Then set DataSource in first line of dtGrid_MouseDoubleClick:
ReportType[] list = new ReportType[] {
new ReportType(1, "Type 1"),
new ReportType(2, "Type 2"),
};
windowToOpen.cmb_UtilityRptTyp.DataSource = list;
windowToOpen.cmb_UtilityRptTyp.DisplayMember = "Title";
windowToOpen.cmb_UtilityRptTyp.ValueMember = "ID";
After that you must use the SelectedText instead of Text in ComboBox, like this:
windowToOpen.cmb_UtilityRptTyp.SelectedText = row_selected["RPTTYPE"].ToString();
Also, You can use SelectedIndex, to find item index you could IndexOf like this
string rptType = row_selected["RPTTYPE"].ToString();
int index = windowToOpen.cmb_UtilityRptTyp.Items.IndexOf(rptType );
windowToOpen.cmb_UtilityRptTyp.SelectedIndex = index;
Or use FindStringExact
string rptType = row_selected["RPTTYPE"].ToString();
int index = windowToOpen.cmb_UtilityRptTyp.FindStringExact(rptType );
windowToOpen.cmb_UtilityRptTyp.SelectedIndex = index;
I am currently making a Windows form in Visual Studio 2017.
I have the DataGridView displaying the data from the CSV correctly.
The problem is when the user inputs some data and saves it and then looks at the DataGridView the data doesn't contain the new data until the program is closed and opened again.
So when the user presses the button Save as Preset the csv is updated however the data in the DataGridView is not.
I have searched the web and can't find any solutions and have tried the usual PresetView.Refresh(); and PresetView.Update(); but is seems that that doesn't fix many people problems either.
Button Code:
public void ButtonProperties()
{
SaveCustomPreset.Click += new EventHandler(SaveCustomPreset_Click);
}
Writing to CSV code:
private void DisplayPresetData(string filePath)
{
DataTable dt = new DataTable();
string[] csv_data = System.IO.File.ReadAllLines(filePath);
string[] data_col = null;
int x = 0;
foreach (string text_line in csv_data)
{
data_col = text_line.Split(',');
if(x == 0)
{
for(int i = 0; i <= data_col.Count() -1; i++)
{
dt.Columns.Add(data_col[i]);
}
x++;
}
else
{
dt.Rows.Add(data_col);
}
}
PresetView.DataSource = dt;
}
Button click code:
private void SaveCustomPreset_Click(object sender, EventArgs e)
{
TextWriter txt = new StreamWriter("../../PresetData.csv", true);
txt.WriteLine(CustomPresetName.Text + "," + CustomX.Text + "," + CustomY.Text + "," + CustomZ.Text + "," + Foam.Text);
txt.Close();
PresetView.Refresh();
PresetView.Update();
}
In your code sample, you're creating a new instance of a DataTable type, and then assigning it to your control as a datasource.
thus, your control's datasource is that object instance that was created in that scope.
private void DisplayPresetData(string filePath)
{
DataTable dt = new DataTable();
string[] csv_data = System.IO.File.ReadAllLines(filePath);
string[] data_col = null;
int x = 0;
foreach (string text_line in csv_data)
{
data_col = text_line.Split(',');
if(x == 0)
{
for(int i = 0; i <= data_col.Count() -1; i++)
{
dt.Columns.Add(data_col[i]);
}
x++;
}
else
{
dt.Rows.Add(data_col);
}
}
PresetView.DataSource = dt;
}
Refreshing the control is not going to automatically call this method.
You can do a couple things to handle this:
You can cast the DataSource (which is actually a DataTable type) to DataTable and Add data to it in the SaveCustomPreset EventHandler method scope.
private void SaveCustomPreset_Click(object sender, EventArgs e)
{
var columns = new []
{
CustomPresetName.Text,
CustomX.Text,
CustomY.Text,
CustomZ.Text,
Foam.Text
};
var line = string.Join(",", columns);
using (TextWriter txt = new StreamWriter("../../PresetData.csv", true))
{
txt.WriteLine(line);
}
var dt = (DataTable)PresetView.DataSource;
foreach(var item in columns)
{
dt.Rows.Add(item)
}
}
or, you can call to the DisplayPresetData(string filePath) method in that event handler (or a similar method that reads data off the file and assigns it to PresetView.DataSource)
The benefit of the second implementation is that you can account for modifications on the csv from scenarios outside of your writing to it.
The benefit of the first implementation is performance. (that is, you avoid the stream file reading, buffering, and looping operations in that method, and instead, you would do incremental Adds.)
I have this program where I want to create a button base from Products on my database(ProductTbl). I found a way to do that
Here's the code:
public void DynamicButton() //Function for retrieving record and creating a button for each product
{
string select = "select ProductID,ProductDesc,ProductPrice,ProductPic from ProductTbl" ;
sda = new SqlDataAdapter(select,sqlConn);
sda.Fill(dataTable);
for (int i = 0; i < dataTable.Rows.Count; i++)
{
ExtendedButton prodBtn = new ExtendedButton(); //with ExtendedButton this time
prodBtn._itemName = dataTable.Rows[i][1].ToString();//this asigns the product name to the extended button
prodBtn._itemID = Convert.ToInt32(dataTable.Rows[i][0]);
prodBtn._myPrice = Convert.ToDecimal(dataTable.Rows[i][2]);
prodBtn.BackgroundImageLayout = ImageLayout.Stretch;
prodBtn.Click += new EventHandler(OnButtonClick);
prodBtn.Height = 100;
prodBtn.Width = 100;
System.Drawing.Font f1 = SystemFonts.DefaultFont;
prodBtn.Font = new System.Drawing.Font(f1.FontFamily,f1.Size,FontStyle.Bold);
prodBtn.Text = dataTable.Rows[i][1].ToString();
prodBtn.TextAlign = ContentAlignment.BottomCenter;
prodBtn.ForeColor = Color.White;
prodBtn.BackgroundImageLayout = ImageLayout.Zoom;
toolTip1.Show(prodBtn.Text, prodBtn);
byte[] image = (byte[])dataTable.Rows[i][3];
prodBtn.BackgroundImage = imgConverter.byteArrayToImage(image);
prodBtn.TextAlign = ContentAlignment.MiddleCenter;
flowPanel.Controls.Add(prodBtn);
}
}
//You can see this at codeproject
Now the problem is that whenever i add a product on that table using Stored procedure. I don't know how i can sync updates to the datatable that I use with this one. Any ideas and suggestion will be highly appreciated. Thanks sorry for the long post
You can use ASP.Net Caching with SqlCacheDependency.
See this page for details:
https://msdn.microsoft.com/en-us/library/ms178604.aspx
Due to a flaw in .NET (Microsoft says its intended but I see it as a serious flaw)
If a user empties a combo box (i.e. wants to blank out the value) the selected value does not revert to null instead it keeps the last valid selected value, so when you save with a blank combobox it goes back to the original value.One workaround is to first choose a different option from the drop down, then blank it out and it will work properly. However, that's not something users of an application would prefer.
So is there a way that I can fix this. Or is it possible that I can add an option for "NONE" which will then change the value in the database to NULL. Note: Combobox has data-binding and I was not able to add the option none for Names.
Contents of the Form.Desginer.cs:
private void InitializeComponent()
{
......
this.cmbSecCSR = new System.Windows.Forms.ComboBox();
this.csrBindingSource2 = new System.Windows.Forms.BindingSource(this.components);
.....
//
// pnlCSRs
//
this.pnlCSRs.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnlCSRs.Controls.Add(this.cmbSecCSR);
......
//
// cmbSecCSR
//
this.cmbSecCSR.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.cmbSecCSR.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.cmbSecCSR.DataSource = this.csrBindingSource2;
this.cmbSecCSR.DisplayMember = "Name";
this.cmbSecCSR.FormattingEnabled = true;
this.cmbSecCSR.Location = new System.Drawing.Point(112, 26);
this.cmbSecCSR.Margin = new System.Windows.Forms.Padding(0);
this.cmbSecCSR.Name = "cmbSecCSR";
this.cmbSecCSR.Size = new System.Drawing.Size(184, 21);
this.cmbSecCSR.TabIndex = 2;
this.cmbSecCSR.ValueMember = "Username";
this.cmbSecCSR.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
this.cmbSecCSR.Enter += new System.EventHandler(this.cmbBox_Entered);
//
// csrBindingSource2
//
this.csrBindingSource2.DataMember = "CSR";
this.csrBindingSource2.DataSource = this.productionDS;
//..............
}
Above are the bits and pieces related to this combobox (I'm just fixing bugs in the application, and a newbie in C#.
The contents related to this combobox in the .CS file are the following:
private void loadDetails()
{
this.productionCrewTableAdapter.FillByProductionID(this.productionDS.ProductionCrew, productionID);
cmbSecCSR.DataBindings.Add("SelectedValue", productionMasterBindingSource, "CSR2", true, DataSourceUpdateMode.OnPropertyChanged);
}
private void comboBox_TextChanged(object sender, EventArgs e)
{
ComboBox cmbx = (ComboBox)sender;
if (cmbx.Equals(cmbCamSupplier))
{
}
else if (cmbx.Equals(cmbLGSupplier))
{
}
if (cmbx.Text.Length > 0) return;
cmbx.ResetText();
cmbx.SelectedIndex = -1;
}
private void cmbBox_Entered(object sender, EventArgs e)
{
ComboBox cmb = (ComboBox)sender;
String txt = cmb.Text;
if (cmb.Name.Contains("CSR"))
{
if (cmb != null)
{
((BindingSource)cmb.DataSource).Filter = (cmbOffice.SelectedIndex > -1 ? "Office = '" + cmbOffice.SelectedValue + "' AND " : "") + "IsCSR=1 AND Status=1";
cmb.Text = txt;
}
}
else if (cmb.Name.Contains("RC"))
{
int department = 0;
if (cmb != null)
{
if (cmb.Name.Contains("Camera"))
department = 2;
else if (cmb.Name.Contains("LG"))
department = 3;
else if (cmb.Name.Contains("Power"))
department = 4;
((BindingSource)cmb.DataSource).Filter = (cmbOffice.SelectedIndex > -1 ? "Office = '" + cmbOffice.SelectedValue + "' AND " : "") + "IsCSR=0 AND Status=1 AND (Department = " + department + " OR Department is null OR Department = 0)";
cmb.Text = txt;
}
}
}
If anyone can help me with this issue that I have been struggling with for a while, I'd really really appreciate it.
At the same time to your call clearing values with
this.cmbSecCSR.Items.Clear()
You have to do a
this.cmbSecCSR.Text = ""
or
this.cmbSecCSR.Text = "Default Text"
To clear the selected text in the combobox.
guyz i know how to add data from my list but the problem is how can i retrieve it...?
id delcared my list in GlobalVar.cs:
public static List<string> ViolationRefNumToPrint = new List<string>();
here's the code behind in adding data to my list.....
GlobalVar.ViolationRefNumToPrint.Clear();
for (int i = 0; i < lvviolations.Items.Count; i++)
{
GlobalVar.ViolationRefNumToPrint.Add(((EmpViolationObject)lvviolations.Items[i]).VioRefNum);
}
my question is how can i retrieve it to my list... :(
EDIT
guyz i've used the code below. which is given by #evanmcdonnal. actually i'm goin to use this on my report... and i've used DocumentViewer
here's my code....
ReportDocument reportDocument = new ReportDocument();
string ats = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
StreamReader reader = new StreamReader(new FileStream(ats.ToString() + #"\Template\ReportViolation.xaml", FileMode.Open, FileAccess.Read));
reportDocument.XamlData = reader.ReadToEnd();
reportDocument.XamlImagePath = Path.Combine(ats.ToString(), #"Template\");
reader.Close();
DateTime dateTimeStart = DateTime.Now; // start time measure here
List<ReportData> listData = new List<ReportData>();
int i = 0;
foreach (string item in GlobalVar.ViolationRefNumToPrint)
{
ReportData data = new ReportData();
data.ReportDocumentValues.Add("PrintDate", DateTime.Now);
data.ReportDocumentValues.Add("EmpIDNum", NewIDNumber.ToString());
data.ReportDocumentValues.Add("EmpName", NewEmpName.ToString());
data.ReportDocumentValues.Add("EmpPosition", NewPosition.ToString());
data.ReportDocumentValues.Add("PageNumber",(i + 1));
data.ReportDocumentValues.Add("PageCount", GlobalVar.ViolationRefNumToPrint.Count.ToString());
listData.Add(data);
i++;
}
XpsDocument xps = reportDocument.CreateXpsDocument(listData);
documentViewer.Document = xps.GetFixedDocumentSequence();
// show the elapsed time in window title
Title += " - generated in " + (DateTime.Now - dateTimeStart).TotalMilliseconds + "ms";
the problem here is it give's me error like this....
You have to loop over it and search for the item you want.
foreach (string item in ViolationRefNumToPrint)
{
Console.Out(item);
}
If instead you want a specific item (assume your list has objects call it string itemImLookinFor = "some nonsense"; loop over it with a conditional to match;
foreach (MyObject item in ViolationRefNumToPrint)
{
if (item.name == itemImLookinFor)
//do something with this object
}