Search This Blog

Thursday, December 12, 2013

How to delete rows from DataGridView without delete rows from DataTable

C# > System.Data   > DataGridView > Delete rows

How to delete rows from DataGridView without delete rows from DataTable?

Solution

Copy original DataTable

Example:


  DataTable dt1 = dt.Copy();
  dataGridView1.DataSource = dt1;


 
 




Wednesday, December 11, 2013

Delete row from DataTable using LINQ VB.NET example

VB.NET > DataTable > Delete row with LINQ

Here is an example of deleting row from DataTable (dt) supposing you want to delete the row with id 1.


Dim row As DataRow = dt.AsEnumerable().SingleOrDefault(Function(r) r(0) = 1)


If Not row Is Nothing Then
    row.Delete()
End If
 
 





Add AutoIncrement Row Values to DataTable Having AutoIncrement and PrimaryKey DataColumn

VB.NET > DataGridView > Add AutoIncrement Row Values

Example how to add AutoIncrement and PrimaryKey DataColumn values to DataTable








VB.NET


  Dim dt As DataTable = New DataTable

  dt.Columns.Add("ID", GetType(Integer))
  dt.PrimaryKey = New DataColumn() {dt.Columns("ID")}
  dt.Columns("ID").AutoIncrement = True
  dt.Columns("ID").AutoIncrementSeed = 1
  dt.Columns("ID").ReadOnly = True

  dt.Columns.Add("Name", GetType(String))

  Dim dr = dt.NewRow()
  dr("Name") = "John"
  dt.Rows.Add(dr)

  dr = dt.NewRow()
  dr("Name") = "Dan"
   dt.Rows.Add(dr)

  DataGridView1.DataSource = dt

C#

DataTable dt = new DataTable();

dt.Columns.Add("ID", typeof(int));
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
dt.Columns["ID"].AutoIncrement = true;
dt.Columns["ID"].AutoIncrementSeed = 1;
dt.Columns["ID"].ReadOnly = true;

dt.Columns.Add("Name", typeof(string));

dynamic dr = dt.NewRow();
dr("Name") = "John";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr("Name") = "Dan";
dt.Rows.Add(dr);

DataGridView1.DataSource = dt;





c# font Italic label example

C# > Drawing > Font > Italic

Italic indicates when Font is italic.

Example:

label1.Font = new System.Drawing.Font(label1.Font, FontStyle.Italic);





Tuesday, December 10, 2013

C# Create new bitmap example

C# > Drawing > Bitmap

Bitmap contains  pixel data for a graphics image. You can save bitmap to GDI+ file formats: BMP, GIF, EXIF, JPG, PNG and TIFF.

Example
Create new bitmap in runtime


Bitmap bmp = new System.Drawing.Bitmap(200, 200);
for (int x = 0; x < bmp.Height; ++x)
   for (int y = 0; y < bmp.Width; ++y)
     bmp.SetPixel(x, y, Color.Coral );
for (int x = 0; x < bmp.Height / 2; ++x)
   for (int y = 0; y < bmp.Width / 2; ++y)
     bmp.SetPixel(x, y, Color.Blue );
pictureBox1.Image = bmp;






C# Drawing Font

C# > Drawing > Font

With Font you can format text and set properties like face, size, style.

FontStyle Enumeration




C# Drawing

C# > Drawing

Provides methods for drawing to the display device using GDI+ basic graphics functionality.
Examples