Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
Visual C# Samples

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual C# Samples 
Visual C# Samples 

You can access sample code by browsing the sample abstracts in this section. Each abstract contains a link to open or copy the sample's files. In addition, the .NET Framework SDK includes technology and application samples, and QuickStart tutorials that demonstrate .NET Framework features and Visual C# code.

The QuickStart Tutorials are the fastest way to understand what the .NET Framework technology offers leading-edge developers. The QuickStarts are a series of samples and supporting documentation designed to quickly acquaint you with the syntax, architecture, and power of Visual Studio and the .NET Framework. The QuickStart tutorials include samples on the ASP.NET and Windows Forms applications, in addition to many how-to applications that cover the most compelling features of the .NET Framework technology.

To access the QuickStarts, click Start, point to Programs, point to Microsoft .NET Framework SDK v2.0, and then click QuickStart Tutorials. A Web page of the "Microsoft .NET Framework SDK QuickStart Tutorials" application is displayed. To run the QuickStarts, follow the directions on this page, which sets up the samples database and completes the installation. For more information, see Samples and QuickStarts.

NoteNote

Visual C# Express users will see the following message when you open the Visual Studio solution (.sln) file for each of these samples: " Solution Folders are not supported in this version of Visual Studio. Solution Folder 'Solution Items' will be displayed as unavailable." Although this folder is not available in Visual C# Express, you can still build and run the projects.

In This Section

Introductory Samples

Anonymous Delegates Sample

Demonstrates the use of unnamed delegates to reduce application complexity.

Arrays Sample

Shows how to use arrays.

Collection Classes Sample

Shows how to make non-generic collection classes that can be used with the foreach statement.

Generics Sample (C#)

Shows how to make generic collection classes that can be used with the foreach statement.

Command Line Parameters Sample

Demonstrates simple command-line processing and array indexing.

Conditional Methods Sample

Demonstrates conditional methods, which provide a powerful mechanism by which calls to methods can be included or omitted depending on whether a symbol is defined.

Delegates Sample

Shows how delegates are declared, mapped, and combined.

Events Sample

Shows how to use events in C#.

Explicit Interface Implementation Sample

Demonstrates how to explicitly implement interface members.

Hello World Sample

A Hello World application.

Indexers Sample

Shows how to use array notation to access an object.

Indexed Properties Sample

Shows how to implement a class that uses indexed properties. Indexed properties allow you to use a class that represents an array-like collection of several different kinds of things.

Properties Sample

Shows how properties are declared and used; also demonstrates abstract properties.

Structs Sample

Shows how to use structs in C#.

Operator Overloading Sample

Shows how user-defined classes can overload operators.

User-Defined Conversions Sample

Shows how to define conversions to and from user-defined types.

Versioning Sample

Demonstrates versioning in C# through the use of the override and new keywords.

Yield Sample

Demonstrates the yield keyword to filter items in a collection.

Intermediate and Advanced Samples

Attributes Sample

Shows how to create custom attribute classes, use them in code, and query them through reflection.

COM Interop Part 1 Sample

Shows how to use C# to interoperate with COM objects.

COM Interop Part 2 Sample

Shows how to a use a C# server with a C++ COM client.

Libraries Sample

Shows how to use compiler options to create a DLL from multiple source files; also, how to use the library in other programs.

Nullable Sample

Demonstrates value types that can be set to null.

OLE DB Sample

Demonstrates how to use a Microsoft Access database from C#. It shows how you can create a dataset and add tables to it from a database.

Partial Types Sample

Demonstrates how classes and structures can be defined in multiple C# source-code files.

Platform Invoke Sample

Shows how to call exported DLL functions from C#.

Security Sample

Discusses .NET Framework security and shows two ways to modify security permissions in C#: using permission classes and permission attributes.

Threading Sample

Demonstrates various thread activities such as creating and executing a thread, synchronizing threads, interacting between threads, and using a thread pool.

Unsafe Code Sample

Shows how to use pointers.

XML Documentation Sample

Shows how to document code by using XML.

Related Sections

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Manipulating Rows in a Data Grid (moving rows up and down in a list)      TheAccidentalCoder ... tottosimon   |   Edit   |   Show History

private void gridRelatedDataRows_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{
int idx=e.Item.ItemIndex;
ArrayList c = new ArrayList();
if( ViewState["RelatedRows"] != null )

{
c = (ArrayList)ViewState["RelatedRows"];

}
int tempCount = c.Count;
RelatedDataRows tempRpm1 = new RelatedDataRows();
RelatedDataRows tempRpm2 = new RelatedDataRows();


if(idx > 0 && e.CommandName == "Up")
{
tempRpm1 = (RelatedDataRows) c[idx];
tempRpm2 = (RelatedDataRows) c[idx - 1];
c.RemoveAt(idx);
c.RemoveAt(idx-1);
c.Insert(idx-1,tempRpm1);
c.Insert(idx,tempRpm2);

}
else if(idx < tempCount-1 && e.CommandName == "Down")
{


tempRpm1 = (RelatedDataRows) c[idx];
tempRpm2 = (RelatedDataRows) c[idx + 1];
c.RemoveAt(idx);
c.RemoveAt(idx);
c.Insert(idx,tempRpm2);
c.Insert(idx+1,tempRpm1);
}



for(int i=0; i<c.Count; i++)
{

RelatedDataRows tempRpm = new RelatedDataRows();
tempRpm = (RelatedDataRows)c[i];



if(i == 0)
{
tempRpm.HeaderMessage="<b>Data Row Description</b>";
}


else
tempRpm.HeaderMessage="<b>which is a:</b>";

c.RemoveAt(i);
c.Insert(i,tempRpm);
}

ViewState["RelatedRows"]= c;

this.gridRelatedDataRows.DataSource = c;
this.gridRelatedDataRows.DataBind();


}

Datagrid Manipulation - Changing population of datagrid based upon a drop-down selection drawn from external data source      TheAccidentalCoder   |   Edit   |   Show History
  private void listRows_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   if(listRows.SelectedValue != "--Select a Data Row--" && listRows.SelectedValue != "--No Data Available--")
   {
    string dbsource1string = System.Configuration.ConfigurationSettings.AppSettings["<DBSOURCE1>"];
    string dbsource2String = System.Configuration.ConfigurationSettings.AppSettings["<DBSOURCE2>"];
    string id = this.listRows.SelectedValue;
    SqlDataReader dr;
    SqlParameter[] p = new SqlParameter[1];
    p[0] = new SqlParameter("@AppId", id);
    dr = SqlHelper.ExecuteReader(connectionString, "GetDataRows", p);
    if( dr.Read() )
    {
     this.txtDataValue1.Text  = dr["DataValue1"].ToString();
     try{this.txtDataValue2.Text = DateTime.Parse(dr["DataValue2"].ToString()).ToShortDateString();}
     catch{}
     this.listValue3.SelectedItem.Text = dr["Value3"].ToString();
     ViewState["DataValue4"] = dr["DataValue4"].ToString(); 
    }
   }
  }
Tags What's this?: Add a tag
Flag as ContentBug
Datdsxsdesd      TheAccidentalCoder ... Thomas Lee   |   Edit   |   Show History

private void Button3_Click(object sender, System.EventArgs e)

String dbsource1String = Sytem>configurationSettings.Appsettings Start
SqlDataReader Dr1;
Sqlparameter P = New Sqlparameter [ 1 ]


int flag=0;
if(listDataRows.Visible==true)
{
if(listDataRows.SelectedValue != "--Select a Data Row--")
{
if(this.listDataRows.SelectedIndex>-1)

string dbsource1string = System.Configuration.ConfigurationSettings.AppSettings["<DBSOURCE1>"];
string dbsource2String = System.Configuration.ConfigurationSettings.AppSettings["<DBSOURCE2>"];
string id = this.listRows.SelectedValue;
SqlDataReader dr;
SqlParameter[] p = new SqlParameter[1];

flag = 1 ;
{ ......................... }
{ ................................. }

else if(listDataRows.Visible==false)
String Dbsource3string = System.cofiguration.configurationSetting.Appsettings Select A Data Row
Sqlparameter { } p + new SqlParameter [2]
flag = 2;

if(flag != 0)
{break;}

temp worker flow chart ( workflow .related data row )
{ }
rpm.FilingDate = this.txtDataValue2.Text;

rpm.ApplicationNumber = this.txtDataValue3.Text;
Sqlparameter [ ] p = New SqlParameter [ 2 ]

if(listDataValue4.SelectedItem.Text == "--------Select Status--------" )
rpm.Status = "";
else
rpm.Status = this.listDataValue4.SelectedItem.Text;

if(flag==1)
listDataValue4.Items.Insert(0,"--------Select Status--------");

if(ViewState["strTitle"] != null)
Extensible Hypertext Markup Language
rpm.TitleMessage = ViewState["strTitle"].ToString();

ArrayList rms = new ArrayList();
if( ViewState["RelatedDataRows"] != null )

rms = (ArrayList) ViewState ["RelatedDataRows"];

HYPERTEXT MARKUP LANGUAGE { HTML}
rms.Add(rpm);
if(rms.Count > 0 )

is.listdatarows.selectedindex+0
RelatedDataRow tempRpm = new RelatedDataRow();
tempRpm = (RelatedDataRow)rms[0];

............... {xhtml} ........................................


tempRpm.HeaderMessage="<b>Data Row Description</b>";
rms.RemoveAt(0);
rms.Insert(0,tempRpm);

ViewState["RelatedDataRows"] = rms;
BindRelatedDataRows();

this.listDataRows.SelectedIndex=0;
this.listDataValue1.SelectedIndex=0;

this.txtDataValue2.Text="";

this.txtDataValue3.Text="";
this.listDataValue4.SelectedIndex=0;

this data value evaluate + sum

relted data row temp + data row

...............................................HTML.................................................

else

this.listDataRows.SelectedIndex=0;
this.listDataValue1.SelectedIndex=0;

this.txtDataValue2.Text="";
this.txtDataValue3.Text="";

this.listDataValue4.SelectedIndex=0;
ShowAlert("This Data Row was already Added.");
}
}
}


End............................. Listdata row............and den Viewstate {Relate data row "}

Tags What's this?: code (x) sample (x) Add a tag
Flag as ContentBug
Datagrid - Binding changes made to a datagrid      TheAccidentalCoder ... 阿朱   |   Edit   |   Show History

private void BindRelatedDataRows()
{
ArrayList c = new ArrayList();
if( ViewState["RelatedDataRows"] != null )
{
c = (ArrayList)ViewState["RelatedDataRows"];
}

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker