Onteora Software

Ken Tucker's Blog
posts - 145, comments - 623, trackbacks - 0

Linq

Paging a Windows Forms DataGridView with LINQ

Since Visual Studio 2008 is due out by the end of the Month I am updating some of my datagridview samples for LINQ. To start off create a new windows forms application in VS 2008 make sure you select FrameWork 3.5 so you can use linq       I now added a new Linq to Sql designer to the project and named it Northwind.  Drag the Northwind Products Table on to the design surface from the Server Explorer.           On your windows forms add a DataGridView (DataGridView1) and a NumericUpDown control (nuPage).  For this...

posted @ Sunday, October 11, 2009 5:48 AM | Feedback (1) | Filed Under [ DataGridView Linq VS 2008 ]

Datagridview and Linq issue

I had some one ask me an interesting question about using linq with the datagridview When I bind a datagridview to this query Dim names() As String = {"hello11", "hello212", "hello123", "hello124", "hello2325", "hello336", "hello457"} Dim query = From s In names _             Order By s _             Select s Dim bs As New BindingSource bs.DataSource = query DataGridView1.DataSource = bs Why do I get these results? The answer the datagridview will show the properties of the class in the list bound to the datagridview.  In this case we are bound to a list of string and the only bindable property is its Length.  ...

posted @ Monday, January 28, 2008 2:40 AM | Feedback (6) | Filed Under [ DataGridView Linq VB ]

Use Linq to create a random list of numbers

Here is a simple linq query which places the numbers from 1 and 150 in a random order   Dim r As New Random(Now.Ticks Mod Int32.MaxValue) Dim rndLst = From l In (From num In Enumerable.Range(1, 150) _              Select New With {.Num = num, .pos = r.Next(1, 150)}) _              Order By l.pos _              Select l.Num For Each i In rndLst     Console.WriteLine(i) Next

posted @ Sunday, January 27, 2008 5:44 AM | Feedback (3) | Filed Under [ Linq VB VS 2008 ]

Linq to DataSet

Linq allows you to query the data in a dataset.  For this example I load the Products and Categories table from the Northwind Database.  I then do a join query to export the Product Name, Unit Price, and Category Name into a list which I display in a datagridview.  Note a query of this type will not display in a datagridview you need to set the datasource equal to the query's Tolist method. Imports System.Data.SqlClient Public Class Form1     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Dim strConn As String = _                 "Server = .\SQLEXPRESS;Database...

posted @ Thursday, November 29, 2007 3:13 AM | Feedback (1) | Filed Under [ Linq VB VS 2008 ]

Using Linq to XML to create an excel spreadsheet

For this example we are going to create a Excel 2007 spreadsheet using the Microsoft OpenXml Sdk and Linq to XML. To start with lets create a new Windows forms app which targets the .Net Framework 3.5.  Add a Linq to Sql design surface to your project and name it Northwind and drag the Northwind Products table on to the surface.  On the windows form I added a DataGridview to display the data we are going to export to excel.  We also need a button named btnExport on the form. To create a excel spreadsheet we need to use the...

posted @ Saturday, November 24, 2007 4:34 PM | Feedback (3) | Filed Under [ Linq open xml xml ]

Using XLinq to get a list of Photos from Spaces.Live.com

Using XLinq to get a list of Photos from Spaces.Live.com Storing photo albums on line is becoming very popular. Spaces.Live.com photo is one place to store albums which exposes its photo albums via an rss feed. I thought it would be nice to test out Visual Studio 2008 XLinq by getting a list of Photo's from the Tampa Code Camp and display them in WPF Listbox. The photos I am looking for can be found here. http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/feed.rss The xml in the rss feed exposes each photo like this     <item>       <title>volunteers arrived at 630am - nikita polyakov [mvp] led them</title>       <link>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134</link>       <description><p><a href="http://thedevfish.spaces.live.com&#47;photos&#47;cns&#33;75364D9E73295107&#33;133&#47;cns&#33;75364D9E73295107&#33;134" mce_href="http://thedevfish.spaces.live.com&#47;photos&#47;cns&#33;75364D9E73295107&#33;133&#47;cns&#33;75364D9E73295107&#33;134"><img src="http://storage.live.com&#47;items&#47;75364D9E73295107&#33;134&#58;thumbnail"...

posted @ Sunday, September 16, 2007 3:39 PM | Feedback (0) | Filed Under [ Asp Linq ]

Using Linq for Master Detail in a DataGridView

Using Linq for Master Detail in a DataGridView I saw in the MSDN forums someone asking how to do a master details relationship with Linq. It is actually pretty simple. Here are the steps involved on creating the relationship. I am using VS 2008 Beta 2 for this example. Open up Visual Studio 2008 Beta 2 and create a windows forms Application Add a new Linq 2 Sql classes to the project named Northwind.dbml Drag the Northwind database's Orders and Order Details table onto the surface Save the project and build it Open the data sources window and add a new object data source. Select...

posted @ Sunday, September 16, 2007 1:51 PM | Feedback (2) | Filed Under [ DataGridView Linq ]

Powered by: