Using Csharp Listview Object

21.03.2025
340
Using Csharp Listview Object

While working with C#, let’s talk a little bit about the Listview object that presents the data you pull from the database to the user by pouring it into the table.

Listview Object

First of all, let’s create the Listview object from the Toolbax section of the Visual Studio program by dragging it onto the form.

After making the necessary sizing, click the right arrow button at the top right of the listview object and click the“Edit Columns” link in the window that opens. After determining the columns of the fields we will pull from the database and the titles of these columns, we will come to the click event of the button that will run the program and write the codes as follows.

<span style="color: #0000ff;">Public Static Void </span>button1_Click(<span style="color: #0000ff;">object </span>sender, <span style="color: #008000;">EventArgs</span> e)

{

list_dokum.Items.Clear();
<span style="color: #008000;">SqlConnection</span> con = <span style="color: #0000ff;">new</span> <span style="color: #008000;">SqlConnection</span>(<span style="color: #993300;">"server=localhost;database=dbase;user id=sa;password=123456"</span>);
<span style="color: #008000;">SqlCommand </span>cmd = <span style="color: #0000ff;">new</span> <span style="color: #008000;">SqlCommand</span>(<span style="color: #993300;">"SELECT * FROM tablo WHERE soyadi LIKE '" + txt_soyadi.Text + "%'AND dogum_tarih LIKE '" + txt_dogum.Text + "%' ORDER BY id DESC"</span>, con);
con.Open();
<span style="color: #008000;">SqlDataReader</span> rdr = cmd.ExecuteReader();

if (rdr.HasRows)
{

while (rdr.Read())
{
<span style="color: #008000;">ListViewItem</span> lst = new <span style="color: #008000;">ListViewItem</span>();
lst.Text = rdr[<span style="color: #993300;">"v_no"</span>].ToString();
lst.SubItems.Add(rdr[<span style="color: #993300;">"adi"</span>].ToString());
lst.SubItems.Add(rdr[<span style="color: #993300;">"soyadi"</span>].ToString());
lst.SubItems.Add(rdr[<span style="color: #993300;">"babaadi"</span>].ToString());

lst.Tag = rdr["id"];
list_dokum.Items.Add(lst);

}

}
HTML

MAKE A COMMENT
COMMENTS - 0 COMMENTS

No comments yet.

Bu web sitesi, bilgisayarınıza bilgi depolamak amacıyla bazı tanımlama bilgilerini kullanabilir.
Bu bilgilerin bir kısmı sitenin çalışmasında esas rolü üstlenirken bir kısmı ise kullanıcı deneyimlerinin iyileştirilmesine ve geliştirilmesine yardımcı olur.
Sitemize ilk girişinizde vermiş olduğunuz çerez onayı ile bu tanımlama bilgilerinin yerleştirilmesine izin vermiş olursunuz.
Çerez bilgilerinizi güncellemek için ekranın sol alt köşesinde bulunan mavi kurabiye logosuna tıklamanız yeterli. Kişisel Verilerin Korunması,
Gizlilik Politikası ve Çerez (Cookie) Kullanımı İlkeleri hakkında detaylı bilgi için KVKK&GDPR sayfamızı inceleyiniz.
| omersahin.com.tr |
Copyright | 2007-2025