Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Bind to datagridview

Bind to datagridview

Scheduled Pinned Locked Moved LINQ
database
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #1

    I feel like a dummy asking this but dammed if I can get it right. I have 2 datatables and I need to do a left join so using the MSDN sample this gets me an AsEnumerable of datarows. I want to bind this to a DGV. So far the most useful has been to use AsDataView(). However this will not allow a join in the query. So what am I doing wrong.

    var Result = from Q in dtQ.AsEnumerable()
    	 join A in dtMap.AsEnumerable()
    	 on Convert.ToString(Q.Field("IssuerID")) equals
    	 A.Field("IDValue")
    	 select new
    	 {
    		 IssuerID = Q.Field("IssuerID"),
    		 AttrID = A.Field("IDValue")
    	 };
    		
    	dgResult.DataSource = Result;
    

    Never underestimate the power of human stupidity RAH

    I 1 Reply Last reply
    0
    • M Mycroft Holmes

      I feel like a dummy asking this but dammed if I can get it right. I have 2 datatables and I need to do a left join so using the MSDN sample this gets me an AsEnumerable of datarows. I want to bind this to a DGV. So far the most useful has been to use AsDataView(). However this will not allow a join in the query. So what am I doing wrong.

      var Result = from Q in dtQ.AsEnumerable()
      	 join A in dtMap.AsEnumerable()
      	 on Convert.ToString(Q.Field("IssuerID")) equals
      	 A.Field("IDValue")
      	 select new
      	 {
      		 IssuerID = Q.Field("IssuerID"),
      		 AttrID = A.Field("IDValue")
      	 };
      		
      	dgResult.DataSource = Result;
      

      Never underestimate the power of human stupidity RAH

      I Offline
      I Offline
      Ian McCaul
      wrote on last edited by
      #2

      Doing a left join is a little odd in linq... try this.

      var Result =
      from Q in dtQ.AsEnumerable()
      join A in dtMap.AsEnumerable() on Convert.ToString(Q.Field("IssuerID"))
      equals A.Field("IDValue") into group
      from g in group.DefaultIfEmpty()
      select new
      {
      IssuerID = Q.Field("IssuerID"),
      AttrID = g.Field("IDValue")
      };
      dgResult.DataSource = Result;
      dgResult.DateBind();

      I think this may do it. Cant tell 100% without trying this myself. But this is how I have done left joins in linq.

      M 1 Reply Last reply
      0
      • I Ian McCaul

        Doing a left join is a little odd in linq... try this.

        var Result =
        from Q in dtQ.AsEnumerable()
        join A in dtMap.AsEnumerable() on Convert.ToString(Q.Field("IssuerID"))
        equals A.Field("IDValue") into group
        from g in group.DefaultIfEmpty()
        select new
        {
        IssuerID = Q.Field("IssuerID"),
        AttrID = g.Field("IDValue")
        };
        dgResult.DataSource = Result;
        dgResult.DateBind();

        I think this may do it. Cant tell 100% without trying this myself. But this is how I have done left joins in linq.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Thanks Ian, first blush has a number of errors with typing, I'll chase them down in the morning. I thought databind was only for the asp GridView, I'm using winforms datagridview.

        Never underestimate the power of human stupidity RAH

        I 1 Reply Last reply
        0
        • M Mycroft Holmes

          Thanks Ian, first blush has a number of errors with typing, I'll chase them down in the morning. I thought databind was only for the asp GridView, I'm using winforms datagridview.

          Never underestimate the power of human stupidity RAH

          I Offline
          I Offline
          Ian McCaul
          wrote on last edited by
          #4

          My bad I thought it was asp.net. Correct you dont need that for winforms.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups