Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Regards,
Karthikeyan.
Posted 5-Sep-12 2:08am
Edited 5-Sep-12 3:47am
v6
Comments
sjelen at 5-Sep-12 10:19am
   
How does your datasource looks like?
Maybe DetailsView would be more appropriate in this case.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Result is ...
 

namespace WinTest
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;
 
///
/// Clean up any resources being used.
///

/// 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
 
///
/// 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)
{
 
}
}
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 405
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 284
3 George Jonsson 265
4 King_Fisher 180
0 Sergey Alexandrovich Kryukov 10,899
1 Maciej Los 5,594
2 OriginalGriff 5,544
3 CPallini 3,819
4 BillWoodruff 3,579


Advertise | Privacy | Mobile
Web04 | 2.8.141030.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100