我是靠谱客的博主 落后哑铃,最近开发中收集的这篇文章主要介绍C#之常用控件集合(英文版),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

The ListView control is an ItemsControl that is derived from ListBox.

c# listview

Add Columns in ListView

You can add columns in Listview by using Columns.Add() method. This method takes two arguments, first one is the Column heading and second one the column width.

listView1.Columns.Add("ProductName", 100);

In the above code, "ProductName" is column heading and 100 is column width.

Add Item in Listview

You can add items in listbox using ListViewItem which represents an item in a ListView control.

string[] arr = new string[4];
ListViewItem itm;//add items to ListView
arr[0] = "product_1";
arr[1] = "100";
arr[2] = "10";
itm = new ListViewItem(arr);
listView1.Items.Add(itm);

Get selected item from ListView

productName = listView1.SelectedItems[0].SubItems[0].Text;

Above code will return the itme from first column of first row.

Sorting Listview Items

If the Sorted property of Listview is set to true, then the ListView items are sorted. The following code sorts the ListView items:

ListView1.Sorted = true;

Add Checkbox in Listview

You can add checkbox in Listview columns.

myListView.CheckBoxes = true;myListView.Columns.Add(text, width, alignment);

c# listview example

ListView provides a large number of properties that provide flexibility in appearance and behavior. The View property allows you to change the way in which items are displayed. The SelectionMode property for a ListView determines how many items a user can select at one time.

The following C# program first set its view property as Details and GridLines property as true and FullRowSelect as true.

listView1.View = View.Details;listView1.GridLines = true;listView1.FullRowSelect = true;

Finally at the button click event, it will display the selected row values in a message box.



Download Source Code
Print Source Code

using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
//Add column header
listView1.Columns.Add("ProductName", 100);
listView1.Columns.Add("Price", 70);
listView1.Columns.Add("Quantity", 70);
//Add items in the listview
string[] arr = new string[4];
ListViewItem itm ;
//Add first item
arr[0] = "product_1";
arr[1] = "100";
arr[2] = "10";
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
//Add second item
arr[0] = "product_2";
arr[1] = "200";
arr[2] = "20";
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
}
private void button1_Click(object sender, EventArgs e)
{
string productName = null;
string price = null;
string quantity = null;
productName = listView1.SelectedItems[0].SubItems[0].Text;
price = listView1.SelectedItems[0].SubItems[1].Text;
quantity = listView1.SelectedItems[0].SubItems[2].Text;
MessageBox.Show (productName + " , " + price + " , " + quantity);
}
}
}

  • C# Visual Studio IDE
  • How to Create a C# Windows Forms Application
  • C# Label Control
  • C# Button Control
  • C# TextBox Control
  • C# ComboBox
  • C# ListBox Control
  • C# Checked ListBox Control
  • C# RadioButton Control
  • C# CheckBox Control
  • C# PictureBox Control
  • C# ProgressBar Control
  • C# ScrollBars Control
  • C# DateTimePicker Control
  • C# Treeview Control
  • C# Menu Control
  • C# MDI Form
  • C# Color Dialog Box
  • C# Font Dialog Box
  • C# OpenFile Dialog Box
  • C# Print Dialog Box
  • keyPress event in C# , KeyDown event in C# , KeyUp event in C#
  • How to create Dynamic Controls in C# ?
  • Keep Form on Top of All Other Windows
  • C# Timer Control



name="fb_xdm_frame_http" frameborder="0" allowtransparency="true" allowfullscreen="true" scrolling="no" id="fb_xdm_frame_http" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tabindex="-1" src="http://static.ak.facebook.com/connect/xd_arbiter/R_qmi4A5CC2.js?version=41#channel=f38e92f438&origin=http%3A%2F%2Fcsharp.net-informations.com" style="border-style: none; border-width: initial;"> name="fb_xdm_frame_https" frameborder="0" allowtransparency="true" allowfullscreen="true" scrolling="no" id="fb_xdm_frame_https" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tabindex="-1" src="https://s-static.ak.facebook.com/connect/xd_arbiter/R_qmi4A5CC2.js?version=41#channel=f38e92f438&origin=http%3A%2F%2Fcsharp.net-informations.com" style="border-style: none; border-width: initial;">
name="oauth2relay1166878498" id="oauth2relay1166878498" src="https://accounts.google.com/o/oauth2/postmessageRelay?parent=http%3A%2F%2Fcsharp.net-informations.com#rpctoken=728550285&forcesecure=1" tabindex="-1" style="font-family: 微软雅黑;font-size:14px; width: 1px; height: 1px; position: absolute; top: -100px;">
  • An overview of Microsoft C#
  • C# Language Tutorial
  • C# Statements Tutorial
  • C# Graphical User Interface Tutorial


  • C# Collection Tutorial
  • C# String Tutorial
  • C# File Operations Tutorial
  • C# Excel Tutorial
  • C# Crystal Reports Tutorial
  • CSharp Communication Tutorial
  • C# Ado.Net Tutorial and Source Code , c# database programming tutorial
  • C# ADO.NET data Providers Tutorial
  • C# Dataset Tutorial
  • C# DataAdapater Tutorial
  • Csharp DataView Tutorial
  • Csharp Remoting Tutorial
  • C# XML Tutorial
  • C# DataGridView Tutorial


frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" tabindex="0" vspace="0" width="100%" id="I0_1444139529991" name="I0_1444139529991" src="https://apis.google.com/se/0/_/+1/fastbutton?usegapi=1&size=tall&annotation=none&origin=http%3A%2F%2Fcsharp.net-informations.com&url=http%3A%2F%2Fcsharp.net-informations.com%2Fgui%2Fcs-listview.htm&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.V2k-AL_BMvw.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCMPquLJxrKq4owfMfww4Fw8-z9GDg#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Conload&id=I0_1444139529991&parent=http%3A%2F%2Fcsharp.net-informations.com&pfname=&rpctoken=23133531" data-gapiattached="true" title="+1" style="position: static; top: 0px; width: 50px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 24px;">

最后

以上就是落后哑铃为你收集整理的C#之常用控件集合(英文版)的全部内容,希望文章能够帮你解决C#之常用控件集合(英文版)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部