How to add value to listview in C#

In this article i would like to show you how to add value to listview in C#. Please see example below:
Sample form with listview
Figure 1: Sample form with listview
Description : 
 - I want to get all value from all textboxes and datetimepicker, which are above of listview, insert to listview when I click on Save button. And also I will sum all value of total column in the listview and show its result in total textbox , which below the listview.
Code: 
ListViewItem listitem;
double pro_total=0;

private void BtnSave_Click(object sender, EventArgs e)
{
   double alltotal=0;
   alltotal = (Convert.ToDouble(txtQuality.Text))*(Convert.ToDouble(txtPrice.Text));
           
   //add value to listview
   listitem = listViewdata.Items.Add(txtOrderID.Text);
   listitem.SubItems.Add(DTPorderDate.Text);
   listitem.SubItems.Add(txtQuality.Text);
   listitem.SubItems.Add(txtPrice.Text);
   listitem.SubItems.Add(txtDiscount.Text);
   listitem.SubItems.Add(Convert.ToString(alltotal));
   //sum all value in Total column in Listview
   pro_total = pro_total + alltotal;
           
   //show all sum of alltotal in textbox
   txtalltotal.Text = Convert.ToString(pro_total);


}
Result:

How to add value to listview in C# How to add value to listview in C# Reviewed by BeiLover on 8:35 PM Rating: 5

No comments:

Powered by Blogger.