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. C#
  4. setting usercontrol's datasource that is same as parent form

setting usercontrol's datasource that is same as parent form

Scheduled Pinned Locked Moved C#
helpcsharp
2 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.
  • S Offline
    S Offline
    saneng
    wrote on last edited by
    #1

    hi i m newbie on C# I have created a usercontrol that has a datagridview i use this control on my parent form, the problem is that i want to set the datasource property of my usercontrol the same as my parent form so that gridview shows the data of the datatable of parent form's dataset' my coding is like this is it work fine public partial class UserControl1 : UserControl { public DataSet ds; public DataTable dt; public UserControl1() { InitializeComponent(); } public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } } public DataTable dt { set { this.dt = value; this.dgvSearch.DataMember = dt; } get { return dt; } } or m missing something any sort of help will be highly appreciated Thanks

    N 1 Reply Last reply
    0
    • S saneng

      hi i m newbie on C# I have created a usercontrol that has a datagridview i use this control on my parent form, the problem is that i want to set the datasource property of my usercontrol the same as my parent form so that gridview shows the data of the datatable of parent form's dataset' my coding is like this is it work fine public partial class UserControl1 : UserControl { public DataSet ds; public DataTable dt; public UserControl1() { InitializeComponent(); } public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } } public DataTable dt { set { this.dt = value; this.dgvSearch.DataMember = dt; } get { return dt; } } or m missing something any sort of help will be highly appreciated Thanks

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      saneng wrote:

      public DataSet ds; public DataTable dt;

      Make these variables to private.

      saneng wrote:

      public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } }

      Change the name of this property as you variable and property names are same.

      public Dataset ControlDataSet
      {
      set
      {
      this.ds = value;
      this.dgvSearch.datasource = ds;
      }
      get
      {
      return ds;
      }
      }

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      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