I have this Code of Showing all Records to a Message box using string builder. Now i need to populate the Serialnumbers to a data grid view or list view.
Similar in My First Question
I replace message box with this code in adding the records to list:
private readonly StringBuilder _builder = new StringBuilder().AppendLine();
Private Dataset _dsdata;
private void SerialVerification()
{
// instantiate BAL
var obj = new BusinessLogic();
var fin = new Entity { SerialNumber = txtSerialNumber.Text};
try
{
try
{
//Check if Serial is on DB
_dsdata = obj.SelectSerial(fin);
if (_dsdata.Tables[0].Rows.Count < 1)
{
//Not on DB table then SAVE
try
{
//Message SAVE ON DB
_i++;
_builder.Append(txtSerialNumber.text).AppendLine();
lblcount.Text = @"Unit Count:" + _i;
}
catch (Exception ee)
{
}
}
else
{
_dates Convert.ToDateTime(_dsdata.Tables[0].Rows[0][2].ToString()).ToShortDateString();
if(_dates == DateTime.Today.ToShortDateString())
{
//Check Duplicate
}
else
{
//Message SAVE ON DB
_i++;
_builder.Append(txtSerialNumber.Text).AppendLine();
lblcount.Text = @"Unit Count:" + _i;
}
}
}
catch(Exception ee)
{
}
if(_i>0)
{
listView1.Items.Clear();
foreach(var a in r)
{
var listItem = new ListViewItem(_builder.ToString()) ;
listView1.Items.Add(listItem);
}
//MessageBox.Show(_builder.ToString());
}
else
{
}
}
catch (ApplicationException ex)
{
}
}
It does not creating new line/Row in list view
but just populating only one row. Is there any solution other than using string builder.
Entry of serialnumber:
1
2
3
My list Displays using my sample code:
1
12
123
Correct:
1
2
3
Thanks in regards..
I got the answer
i replace my code to this: