listview in csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace listview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listViewMusteri.View = View.Details; //alt alta gösterir listeyi
//kolonlarımızı ekledik, sola dayalı, boyutu 100 verdik
listViewMusteri.Columns.Add("Ad", 100,HorizontalAlignment.Left);
listViewMusteri.Columns.Add("Soyad",140, HorizontalAlignment.Left);
listViewMusteri.Columns.Add("Tel", 200,HorizontalAlignment.Left);
}
private void btnEkle_Click(object sender, EventArgs e)
{
int count = listViewMusteri.Items.Count;
bool flag=false;
for(int i=0; i<count; i++)
{
//isim ve soyisim kontrolü, eğer varsa tekrar eklemesin
if (txtAd.Text.Equals(listViewMusteri.Items[i].Text) && txtSoyad.Text.Equals(listViewMusteri.Items[i].SubItems[1].Text))
{
flag = true;
break;
}
}
if (flag)
{
MessageBox.Show("you are already our member..");
txtAd.Clear();
txtSoyad.Clear();
txtTel.Clear();
}
else
{
listViewMusteri.Items.Add(txtAd.Text); //ana kolon bilgisi // 0. kolon
listViewMusteri.Items[count].SubItems.Add(txtSoyad.Text); // 1. alt kolon
listViewMusteri.Items[count].SubItems.Add(txtTel.Text); //2. alt kolon
txtAd.Clear();
txtSoyad.Clear();
txtTel.Clear();
}
}
}
}