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. .NET (Core and Framework)
  4. BindingSource Implementation in .net Win Forms

BindingSource Implementation in .net Win Forms

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpwpfwcfquestion
6 Posts 3 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.
  • R Offline
    R Offline
    rjto
    wrote on last edited by
    #1

    I have 2 .net forms, each with their own BindingSource which I set to go after the same DataTable. The table is filled early on with 35 rows. One of the BindingSources has a filter set when the form loads, which makes the result set 4 rows. When I go back to the first form, the row count has gone down to 4 - if I set that BindingSource filter to "", the count returns to 35. It looks as if the two binding sources are sharing stuff, where changing the filter on one affects the other. Any explanation for this? I am working around it but would like to understand the mechanism. Bob

    P 1 Reply Last reply
    0
    • R rjto

      I have 2 .net forms, each with their own BindingSource which I set to go after the same DataTable. The table is filled early on with 35 rows. One of the BindingSources has a filter set when the form loads, which makes the result set 4 rows. When I go back to the first form, the row count has gone down to 4 - if I set that BindingSource filter to "", the count returns to 35. It looks as if the two binding sources are sharing stuff, where changing the filter on one affects the other. Any explanation for this? I am working around it but would like to understand the mechanism. Bob

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      It's the sharing of the same DataSource that is the issue. When you set the Filter to a none null value, the property is passed down to the underlying data source so you are filtering on the source itself. Source[^].

      This space for rent

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        It's the sharing of the same DataSource that is the issue. When you set the Filter to a none null value, the property is passed down to the underlying data source so you are filtering on the source itself. Source[^].

        This space for rent

        R Offline
        R Offline
        rjto
        wrote on last edited by
        #3

        Thanks, if I read the docs right, it appears if I tie the binding sources to DataViews, not the DataTable, it might work as I intend and keep the filters separate...

        M 1 Reply Last reply
        0
        • R rjto

          Thanks, if I read the docs right, it appears if I tie the binding sources to DataViews, not the DataTable, it might work as I intend and keep the filters separate...

          M Offline
          M Offline
          mtoha
          wrote on last edited by
          #4

          Based on my own experience, I am just need to create public static DataTable datasource which is will be consumed by that 2 or more forms... Not just Datatable, but also collection, We can put it on main Program.cs, let's say it glbData.

          public class Program{
          public static DataTable glbData;
          }

          usage :

          DataTable dt = resultset[0]; //Result From Database
          Program.glbData = dt;

          Regards Toha

          P 1 Reply Last reply
          0
          • M mtoha

            Based on my own experience, I am just need to create public static DataTable datasource which is will be consumed by that 2 or more forms... Not just Datatable, but also collection, We can put it on main Program.cs, let's say it glbData.

            public class Program{
            public static DataTable glbData;
            }

            usage :

            DataTable dt = resultset[0]; //Result From Database
            Program.glbData = dt;

            Regards Toha

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            And how does your solution solve the problem the poster had? Go ahead and try your solution with the problem the OP had.

            This space for rent

            M 1 Reply Last reply
            0
            • P Pete OHanlon

              And how does your solution solve the problem the poster had? Go ahead and try your solution with the problem the OP had.

              This space for rent

              M Offline
              M Offline
              mtoha
              wrote on last edited by
              #6

              I have test this and the first form not affected with changes from FormMahasiswa

              private void FormMahasiswa_Load(object sender, EventArgs e)
              {
              Form1.glbData = new DataTable();
              Form1.glbData.Columns.Add("Newww", typeof(int));
              Form1.glbData.Columns.Add("Drug", typeof(string));
              Form1.glbData.Columns.Add("Patient", typeof(string));
              Form1.glbData.Columns.Add("Date", typeof(DateTime));

                      // Here we add five DataRows.
                      Form1.glbData.Rows.Add(25, "Sample Change", "Change ", DateTime.Now);
                      Form1.glbData.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
                      Form1.glbData.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
                      Form1.glbData.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
                      Form1.glbData.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
                      dataGridView1.DataSource = Form1.glbData;
                  }
              

              Regards Toha

              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