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

本文是小编为大家收集整理的关于用于创建标签和文本框的ListView框字段(c#4.0)的处理方法,想解了用于创建标签和文本框的ListView框字段(c#4.0)的问题怎么解决?用于创建标签和文本框的ListView框字段(c#4.0)问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

你好,
我的 ListView 框项目有两个字段.名称和价值.
示例:

listView 框:=======================名称 值=======================编号 |IT10001姓名 |abc年龄 |30班级 |BE学院|abc学院地址1 |1 交叉城市 |xyz国家 |ABCD---------------------

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

这种方式的例子:
Label1.text=ID文本框1.text=IT10001Label2.text=名称文本框2.text=abc标签文本框----- --------编号:IT10001名称:abc年龄:18类别:BE学院:abc学院地址1:1 交叉,1 主城市:xyz国家:ABCD

问候,
Karthikeyan.

推荐答案

你好,
结果是……


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

///<总结>
///清理所有正在使用的资源.
///
///<param name="disposing"/>如果托管资源应该被释放,则为true;否则为假.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
组件.Dispose();
}
base.Dispose(处置);
}

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

///<总结>
///设计器支持所需的方法 - 请勿修改
///用代码编辑器查看这个方法的内容.
///
私有 void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem12 = new System.Windows.Forms.ListViewItem(new string[] {
"公司名称",
"Soc"}, -1);
System.Windows.Forms.ListViewItem listViewItem13 = new System.Windows.Forms.ListViewItem(new string[] {
"身份证",
"001"}, -1);
System.Windows.Forms.ListViewItem listViewItem14 = new System.Windows.Forms.ListViewItem(new string[] {
"名字",
"卡"},-1);
System.Windows.Forms.ListViewItem listViewItem15 = new System.Windows.Forms.ListViewItem(new string[] {
"姓氏",
"柯"},-1);
System.Windows.Forms.ListViewItem listViewItem16 = new System.Windows.Forms.ListViewItem(new string[] {
"地址1",
"R.T"}, -1);
System.Windows.Forms.ListViewItem listViewItem17 = new System.Windows.Forms.ListViewItem(new string[] {
"地址2",
"80 英尺路"}, -1);
System.Windows.Forms.ListViewItem listViewItem18 = new System.Windows.Forms.ListViewItem(new string[] {
《城市》,
"禁止"}, -1);
System.Windows.Forms.ListViewItem listViewItem19 = new System.Windows.Forms.ListViewItem(new string[] {
"邮编",
"560"}, -1);
System.Windows.Forms.ListViewItem listViewItem20 = new System.Windows.Forms.ListViewItem(new string[] {
"国家",
"卡尔"}, -1);
System.Windows.Forms.ListViewItem listViewItem21 = new System.Windows.Forms.ListViewItem(new string[] {
"国家",
"印度"}, -1);
System.Windows.Forms.ListViewItem listViewItem22 = new System.Windows.Forms.ListViewItem(new string[] {
"网站",
"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();
//
//列表视图3
//
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 = "名称";
this.columnHeader3.Width = 90;
//
//columnHeader4
//
this.columnHeader4.Text = "值";
this.columnHeader4.Width = 94;
//
//btn生成
//
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);
//
//标签1
//
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 = "结果";
//
//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

私有 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
{
诠释我,c;int a=0;
公共Form1()
{
初始化组件();
我 = 60;
}

private void btnGenerate_Click(object sender, EventArgs e)
{
整数 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);

文本框 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);

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

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

本文地址:https://www.itbaoku.cn/post/1355763.html

相关标签/搜索