用于创建Label和TextBox的ListView Box字段(c#4.0) [英] ListView Box field to create Label and TextBox (c# 4.0)

查看:57
本文介绍了用于创建Label和TextBox的ListView Box字段(c#4.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的ListView Box项有两个字段.名称和值.
示例:

Hi,
I my ListView Box Items have two Fields. Name and Value.
Example:

listView Box:
======================
Name     Value
======================
ID       |IT10001
Name     |abc
Age      |30
Class    |BE
College  |abc College
Address1 |1 cross
City     |xyz
Country  |ABCD
---------------------


如何更改每个字段以创建标签和文本框?

这种方式的示例:


How to change each field to create Label and Textbox?

example of this way:

Label1.text=ID
Textbox1.text=IT10001
Label2.text=Name
Textbox2.text=abc


Label    TextBox
-----    --------
ID       :IT10001
Name     :abc
Age      :18
Class    :BE
College  :abc College
Address1 :1 cross,1 main
City     :xyz
Country  :ABCD


问候,
Karthikeyan.


Regards,
Karthikeyan.

推荐答案


结果是...


命名空间WinTest
{
局部类Form1
{
///< summary>
///必需的设计器变量.
///
私有System.ComponentModel.IContainer组件= null;

///< summary>
///清理所有正在使用的资源.
///
///< param name ="disposed"/>如果应该管理托管资源,则为true;否则为false.
受保护的重写void Dispose(布尔处置)
{
if(处理&&(组件!= null))
{
components.Dispose();
}
base.Dispose(处置);
}

#region Windows窗体设计器生成的代码

///< summary>
///支持Designer的必需方法-请勿修改
///使用代码编辑器将此方法的内容.
///
私有void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem12 =新System.Windows.Forms.ListViewItem(新字符串[] {
公司名称",
"Soc"},-1);
System.Windows.Forms.ListViewItem listViewItem13 =新System.Windows.Forms.ListViewItem(新字符串[] {
"ID",
"001"},-1);
System.Windows.Forms.ListViewItem listViewItem14 =新System.Windows.Forms.ListViewItem(新字符串[] {
名字",
"Ka"},-1);
System.Windows.Forms.ListViewItem listViewItem15 =新System.Windows.Forms.ListViewItem(新字符串[] {
姓氏",
"Ke"},-1);
System.Windows.Forms.ListViewItem listViewItem16 =新System.Windows.Forms.ListViewItem(新字符串[] {
"Address1",
"R.T"},-1);
System.Windows.Forms.ListViewItem listViewItem17 =新System.Windows.Forms.ListViewItem(新字符串[] {
"Address2",
"80 Feet Road"},-1);
System.Windows.Forms.ListViewItem listViewItem18 =新System.Windows.Forms.ListViewItem(新字符串[] {
城市",
"Ban"},-1);
System.Windows.Forms.ListViewItem listViewItem19 =新System.Windows.Forms.ListViewItem(新字符串[] {
邮编",
"560"},-1);
System.Windows.Forms.ListViewItem listViewItem20 =新System.Windows.Forms.ListViewItem(新字符串[] {
状态",
"Kar"},-1);
System.Windows.Forms.ListViewItem listViewItem21 =新System.Windows.Forms.ListViewItem(新字符串[] {
国家",
印度"},-1);
System.Windows.Forms.ListViewItem listViewItem22 =新System.Windows.Forms.ListViewItem(新字符串[] {
网站",
"www.soc .... com"},-1);
this.listView3 =新的System.Windows.Forms.ListView();
this.columnHeader3 =(((System.Windows.Forms.ColumnHeader)(新System.Windows.Forms.ColumnHeader()));
this.columnHeader4 =(((System.Windows.Forms.ColumnHeader)(新System.Windows.Forms.ColumnHeader()));
this.btnGenerate = new System.Windows.Forms.Button();
this.label1 =新的System.Windows.Forms.Label();
this.SuspendLayout();
//
//listView3
//
this.listView3.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {
this.columnHeader3,
this.columnHeader4});
listViewItem19.Tag =";
this.listView3.Items.AddRange(new System.Windows.Forms.ListViewItem [] {
listViewItem12,
listViewItem13,
listViewItem14,
listViewItem15,
listViewItem16,
listViewItem17,
listViewItem18,
listViewItem19,
listViewItem20,
listViewItem21,
listViewItem22});
this.listView3.Location =新的System.Drawing.Point(598,22);
this.listView3.Name ="listView3";
this.listView3.Size = new System.Drawing.Size(266,213);
this.listView3.TabIndex = 2;
this.listView3.UseCompatibleStateImageBehavior = false;
this.listView3.View = System.Windows.Forms.View.Details;
//
//columnHeader3
//
this.columnHeader3.Text =名称";
this.columnHeader3.Width = 90;
//
//columnHeader4
//
this.columnHeader4.Text =值";
this.columnHeader4.Width = 94;
//
//btnGenerate
//
this.btnGenerate.Location = new System.Drawing.Point(655,258);
this.btnGenerate.Name ="btnGenerate";
this.btnGenerate.Size = new System.Drawing.Size(156,35);
this.btnGenerate.TabIndex = 4;
this.btnGenerate.Text =生成";
this.btnGenerate.UseVisualStyleBackColor = true;
this.btnGenerate.Click + = new System.EventHandler(this.btnGenerate_Click);
//
//label1
//
this.label1.AutoSize = true;
this.label1.Font =新的System.Drawing.Font("Microsoft Sans Serif",15F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,(((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
this.label1.Location =新的System.Drawing.Point(12,9);
this.label1.Name ="label1";
this.label1.Size =新的System.Drawing.Size(202,25);
this.label1.TabIndex = 5;
this.label1.Text =结果";
//
//Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1041,494);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnGenerate);
this.Controls.Add(this.listView3);
this.Name ="Form1";
this.Text ="Form1";
this.Load + =新的System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

私有System.Windows.Forms.ListView listView3;
私有System.Windows.Forms.ColumnHeader columnHeader3;
私有System.Windows.Forms.ColumnHeader columnHeader4;
私有System.Windows.Forms.Button btnGenerate;
私有System.Windows.Forms.Label label1;
}
}


================================================== =======================
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;

命名空间WinTest
{
公共局部类Form1:Form
{
int i,c; int a = 0;
公共Form1()
{
InitializeComponent();
我= 60;
}

私有void btnGenerate_Click(对象发送者,EventArgs e)
{
int j = 0;
如果(a< = j)
{
for(c = 0; c< listView3.Items.Count; c ++)
{
字符串s = listView3.Items [c] .SubItems [0] .Text;
标签lblName = new Label();
lblName.Name ="lbl" + listView3.Items [c] .SubItems [0] .Text.Trim();
lblName.Left = 50;
lblName.Top = i;
lblName.Text = listView3.Items [c] .SubItems [0] .Text.Trim();
lblName.BorderStyle = BorderStyle.Fixed3D;
lblName.Visible = true;
this.Controls.Add(lblName);

TextBox txtValue = new TextBox();
txtValue.Name ="txt" + listView3.Items [c] .SubItems [1] .Text.Trim();
txtValue.Left = 150;
txtValue.Top = i;
txtValue.Width = 150;
txtValue.Text = listView3.Items [c] .SubItems [1] .Text.Trim();
this.Controls.Add(txtValue);

CheckBox chkActive =新的CheckBox();
chkActive.Name ="chk" + listView3.Items [c] .SubItems [1] .Text.Trim();
chkActive.Left = 20;
chkActive.Top = i;
chkActive.Checked = true;
this.Controls.Add(chkActive);

i = i + 25;
}
}
一个= listView3.Items.Count;
//a = j;
//for(listView3.Items.Count
}

私有void Form1_Load(对象发送者,EventArgs e)
{

}
}
}
Hi,
Result is ...


namespace WinTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
///
/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem12 = new System.Windows.Forms.ListViewItem(new string[] {
"Company Name",
"Soc"}, -1);
System.Windows.Forms.ListViewItem listViewItem13 = new System.Windows.Forms.ListViewItem(new string[] {
"ID",
"001"}, -1);
System.Windows.Forms.ListViewItem listViewItem14 = new System.Windows.Forms.ListViewItem(new string[] {
"First Name",
"Ka"}, -1);
System.Windows.Forms.ListViewItem listViewItem15 = new System.Windows.Forms.ListViewItem(new string[] {
"Last Name",
"Ke"}, -1);
System.Windows.Forms.ListViewItem listViewItem16 = new System.Windows.Forms.ListViewItem(new string[] {
"Address1",
"R.T"}, -1);
System.Windows.Forms.ListViewItem listViewItem17 = new System.Windows.Forms.ListViewItem(new string[] {
"Address2",
"80 Feet Road"}, -1);
System.Windows.Forms.ListViewItem listViewItem18 = new System.Windows.Forms.ListViewItem(new string[] {
"City",
"Ban"}, -1);
System.Windows.Forms.ListViewItem listViewItem19 = new System.Windows.Forms.ListViewItem(new string[] {
"Zip",
"560"}, -1);
System.Windows.Forms.ListViewItem listViewItem20 = new System.Windows.Forms.ListViewItem(new string[] {
"State",
"Kar"}, -1);
System.Windows.Forms.ListViewItem listViewItem21 = new System.Windows.Forms.ListViewItem(new string[] {
"Country",
"India"}, -1);
System.Windows.Forms.ListViewItem listViewItem22 = new System.Windows.Forms.ListViewItem(new string[] {
"WebSite",
"www.soc ....com"}, -1);
this.listView3 = new System.Windows.Forms.ListView();
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.btnGenerate = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// listView3
//
this.listView3.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader3,
this.columnHeader4});
listViewItem19.Tag = "";
this.listView3.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem12,
listViewItem13,
listViewItem14,
listViewItem15,
listViewItem16,
listViewItem17,
listViewItem18,
listViewItem19,
listViewItem20,
listViewItem21,
listViewItem22});
this.listView3.Location = new System.Drawing.Point(598, 22);
this.listView3.Name = "listView3";
this.listView3.Size = new System.Drawing.Size(266, 213);
this.listView3.TabIndex = 2;
this.listView3.UseCompatibleStateImageBehavior = false;
this.listView3.View = System.Windows.Forms.View.Details;
//
// columnHeader3
//
this.columnHeader3.Text = "Name";
this.columnHeader3.Width = 90;
//
// columnHeader4
//
this.columnHeader4.Text = "Value";
this.columnHeader4.Width = 94;
//
// btnGenerate
//
this.btnGenerate.Location = new System.Drawing.Point(655, 258);
this.btnGenerate.Name = "btnGenerate";
this.btnGenerate.Size = new System.Drawing.Size(156, 35);
this.btnGenerate.TabIndex = 4;
this.btnGenerate.Text = "Generate";
this.btnGenerate.UseVisualStyleBackColor = true;
this.btnGenerate.Click += new System.EventHandler(this.btnGenerate_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(202, 25);
this.label1.TabIndex = 5;
this.label1.Text = "Result";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1041, 494);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnGenerate);
this.Controls.Add(this.listView3);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.ListView listView3;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.Button btnGenerate;
private System.Windows.Forms.Label label1;
}
}


===========================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinTest
{
public partial class Form1 : Form
{
int i, c; int a=0;
public Form1()
{
InitializeComponent();
i = 60;
}

private void btnGenerate_Click(object sender, EventArgs e)
{
int j = 0;
if (a <= j)
{
for (c = 0; c < listView3.Items.Count; c++)
{
string s = listView3.Items[c].SubItems[0].Text;
Label lblName = new Label();
lblName.Name = "lbl" + listView3.Items[c].SubItems[0].Text.Trim();
lblName.Left = 50;
lblName.Top = i;
lblName.Text = listView3.Items[c].SubItems[0].Text.Trim();
lblName.BorderStyle = BorderStyle.Fixed3D;
lblName.Visible = true;
this.Controls.Add(lblName);

TextBox txtValue = new TextBox();
txtValue.Name = "txt" + listView3.Items[c].SubItems[1].Text.Trim();
txtValue.Left = 150;
txtValue.Top = i;
txtValue.Width = 150;
txtValue.Text = listView3.Items[c].SubItems[1].Text.Trim();
this.Controls.Add(txtValue);

CheckBox chkActive = new CheckBox();
chkActive.Name = "chk" + listView3.Items[c].SubItems[1].Text.Trim();
chkActive.Left = 20;
chkActive.Top = i;
chkActive.Checked = true;
this.Controls.Add(chkActive);

i = i + 25;
}
}
a = listView3.Items.Count;
//a=j;
//for(listView3.Items.Count
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}


这篇关于用于创建Label和TextBox的ListView Box字段(c#4.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆