C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

ListViewItem


Posted Date: 20 Nov 2008      Posted By: Ravisanker      Member Level: Silver     Points: 1   Responses: 1



Hi

Can i Use ListViewItem class in ASP.NET 2.0
Is there any other Class to do the same function as .....

ListViewItem item = new ListViewItem();
item.SubItems.Add(message1);
item.Tag = message;



plz help , thnkx in adv





Responses

Author: Venkat Tammineni    20 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

hi,

Have a look below code..
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.ListView lvCountries;
private System.Windows.Forms.ImageList imgLarge;
private System.Windows.Forms.ImageList imgSmall;
private System.Windows.Forms.ComboBox cbView;
private System.Windows.Forms.Label lblAbbreviation;
private System.ComponentModel.IContainer components;

public Form1() {
InitializeComponent();
lvCountries.Items.Add(new CountryItem("United States", "US", "Dollar"));
lvCountries.Items[0].ImageIndex = 0;
lvCountries.Items.Add(new CountryItem("Great Britain", "GB", "Pound"));
lvCountries.Items[1].ImageIndex = 1;
lvCountries.Items.Add(new CountryItem("Canada", "CA", "Dollar"));
lvCountries.Items[2].ImageIndex = 2;
lvCountries.Items.Add(new CountryItem("Japan", "JP", "Yen"));
lvCountries.Items[3].ImageIndex = 3;
lvCountries.Items.Add(new CountryItem("Germany", "GM", "Deutch Mark"));
lvCountries.Items[4].ImageIndex = 4;

cbView.Items.Add(View.LargeIcon);
cbView.Items.Add(View.SmallIcon);
cbView.Items.Add(View.List);
cbView.Items.Add(View.Details);
cbView.SelectedIndex = 0;

lvCountries.Columns.Add("Country",100, HorizontalAlignment.Left);
lvCountries.Columns.Add("Currency",100, HorizontalAlignment.Left);
}
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.lvCountries = new System.Windows.Forms.ListView();
this.imgLarge = new System.Windows.Forms.ImageList(this.components);
this.imgSmall = new System.Windows.Forms.ImageList(this.components);
this.cbView = new System.Windows.Forms.ComboBox();
this.lblAbbreviation = new System.Windows.Forms.Label();
this.SuspendLayout();

this.lvCountries.LargeImageList = this.imgLarge;
this.lvCountries.Location = new System.Drawing.Point(24, 72);
this.lvCountries.Name = "lvCountries";
this.lvCountries.Size = new System.Drawing.Size(256, 248);
this.lvCountries.SmallImageList = this.imgSmall;
this.lvCountries.TabIndex = 0;
this.lvCountries.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvCountries_MouseUp);

this.imgLarge.ImageSize = new System.Drawing.Size(48, 48);
this.imgLarge.TransparentColor = System.Drawing.Color.Transparent;

this.imgSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
this.imgSmall.ImageSize = new System.Drawing.Size(16, 16);
this.imgSmall.TransparentColor = System.Drawing.Color.Transparent;
//
// cbView
//
this.cbView.Location = new System.Drawing.Point(32, 32);
this.cbView.Name = "cbView";
this.cbView.Size = new System.Drawing.Size(128, 21);
this.cbView.TabIndex = 1;
this.cbView.SelectedIndexChanged += new System.EventHandler(this.cbView_SelectedIndexChanged);
//
// lblAbbreviation
//
this.lblAbbreviation.Location = new System.Drawing.Point(176, 32);
this.lblAbbreviation.Name = "lblAbbreviation";
this.lblAbbreviation.Size = new System.Drawing.Size(48, 23);
this.lblAbbreviation.TabIndex = 2;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(312, 339);
this.Controls.Add(this.lblAbbreviation);
this.Controls.Add(this.cbView);
this.Controls.Add(this.lvCountries);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
static void Main() {
Application.Run(new Form1());
}

private void cbView_SelectedIndexChanged(object sender, System.EventArgs e)
{
lvCountries.View = (View)cbView.SelectedItem;
}

private void lvCountries_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(lvCountries.View != View.Details)
lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(e.X, e.Y)).CountryAbbreviation;
else
lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(5, e.Y)).CountryAbbreviation;
}


}
public class CountryItem : System.Windows.Forms.ListViewItem {
string countryName = "";
string countryAbbrev = "";

public CountryItem(string countryName, string countryAbbreviation, string currency)
{
countryName = countryName;
countryAbbrev = countryAbbreviation;
base.Text = countryName;
base.SubItems.Add(currency);
}

public string CountryName
{
get {return countryName;}
}

public string CountryAbbreviation
{
get {return countryAbbrev;}
}
}


Thanks



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Encrypt or Decrypt like google ex:DF$$F34sdfsdf234234234234234/////-/=-///
Previous : having a first record selected by default on a Datagrid with Radiobuttons C#
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use