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. BindingList and DataGridView question. [modified]

BindingList and DataGridView question. [modified]

Scheduled Pinned Locked Moved C#
questiondatabasedata-structureshelp
9 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
    sharp source
    wrote on last edited by
    #1

    public class ActiveTable { public string omniwinRoot; public string table; public string tableKey; public int tableRecords; public int tableUniqueRecords; public int diff; public Queue doubleKey = new Queue(); public Queue noNversion = new Queue(); analyzeTable() { // if there is a problem with the index key (eg uniqueness) the id is put in the // doubleKey Queue. } } public class form1 { BindingList bindingList1 = new BindingList(); dataGridView1.DataSource = bindingList1; dataGridView1.AutoGenerateColumns = true; ActiveTable tableToCheck = new AvtiveTable(); // tableTocheck.omniwinRoot is assigned a value from a table // tableTocheck.table is assigned a value from a table // tableTocheck.tableKey is assigned a value from a table tableTocheck.analyseTable(); if (tableToCeck.doubleKey.Count() > 0) { bindingList1.Add(tableToCheck); } } My question is: why doesn't this work. The DataGridView has a datasource and should be able to generate columns, yes? Why doesn't my DataGridView create columns and adds rows when items are added to bindinglist? I've tried lots of different things. Such as defining the columns myself. With defined columns i see that there are rows added to the DataGridView but the columns remain empty. Any suggestions? -- modified at 13:35 Tuesday 29th May, 2007

    D 1 Reply Last reply
    0
    • S sharp source

      public class ActiveTable { public string omniwinRoot; public string table; public string tableKey; public int tableRecords; public int tableUniqueRecords; public int diff; public Queue doubleKey = new Queue(); public Queue noNversion = new Queue(); analyzeTable() { // if there is a problem with the index key (eg uniqueness) the id is put in the // doubleKey Queue. } } public class form1 { BindingList bindingList1 = new BindingList(); dataGridView1.DataSource = bindingList1; dataGridView1.AutoGenerateColumns = true; ActiveTable tableToCheck = new AvtiveTable(); // tableTocheck.omniwinRoot is assigned a value from a table // tableTocheck.table is assigned a value from a table // tableTocheck.tableKey is assigned a value from a table tableTocheck.analyseTable(); if (tableToCeck.doubleKey.Count() > 0) { bindingList1.Add(tableToCheck); } } My question is: why doesn't this work. The DataGridView has a datasource and should be able to generate columns, yes? Why doesn't my DataGridView create columns and adds rows when items are added to bindinglist? I've tried lots of different things. Such as defining the columns myself. With defined columns i see that there are rows added to the DataGridView but the columns remain empty. Any suggestions? -- modified at 13:35 Tuesday 29th May, 2007

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      sharp source wrote:

      BindingList listOfDoubleIndexTables = new BindingList(); dataGridView1.DataSource = Bindinglist1;

      OK. You define a new BindingList, but then you never use it. You bound the DGV to something called BindingList1. So, which list does addItemsToBindingList1 add stuff to? What are those items? What does this code look like? And what does this ActiveTable class have to do with anything?

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        sharp source wrote:

        BindingList listOfDoubleIndexTables = new BindingList(); dataGridView1.DataSource = Bindinglist1;

        OK. You define a new BindingList, but then you never use it. You bound the DGV to something called BindingList1. So, which list does addItemsToBindingList1 add stuff to? What are those items? What does this code look like? And what does this ActiveTable class have to do with anything?

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        S Offline
        S Offline
        sharp source
        wrote on last edited by
        #3

        Sorry, i only wanted the relevant parts of my code. I messed up and should have reread before posting. I made some corrections and added a few lines. Hope it will make more sense. If you want to, http://users.telenet.be/simonsmeets/source.zip[^] holds the project. thx 4 your time... simon

        D 1 Reply Last reply
        0
        • S sharp source

          Sorry, i only wanted the relevant parts of my code. I messed up and should have reread before posting. I made some corrections and added a few lines. Hope it will make more sense. If you want to, http://users.telenet.be/simonsmeets/source.zip[^] holds the project. thx 4 your time... simon

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          That still doesn't help. I have no idea what you're trying to bind the DGV to, or what you're trying to display, or why, ...

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            That still doesn't help. I have no idea what you're trying to bind the DGV to, or what you're trying to display, or why, ...

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            S Offline
            S Offline
            sharp source
            wrote on last edited by
            #5

            Ok, i'll start over. The goal of the application is to check visual foxpro tables of an application named omniwin for numerous different problems. The important one for this problem is the analysis of the index key's uniqueness. First the user selects the root of omniwin. After the root is validated this application checks the data tables for double index keys. All the tables wich have to be checked can be found in a table called tableinfo (tableinfo.dbf) and from that table i take the tablename, index field of table, and location of the file in which it is stored. These variables are stored in an instance of ActiveTable, named tableToAnalyze. Next the table is analysed by invoking tableToAnalyze.CheckForDoubleKey(). That method checks number of rows (tableToAnalyze.tableRecords) and number of distinct(id) rows (tableToAnalyze.tableUniqueRecords). If those values do not match the method stores the not distinct keys in a queue (tableToAnalyze.doubleKey) When the table is checked and tableToAnalyze.doubleKey.count() > 1 the instance tableToAnalyse is added to the BindingList listOfDoubleIndexTables. My intention is to display the BindingList listOfDoubleIndexTables in a DGV on the form. Then I can delete rows before starting a fix method because not all problems should be fixed. Problem: I've added a DGV on the form (desinger) and named it: dataGridDoubleKey I've set the DataSource of the DGV to the appropriate datasource: dataGridDoubleKey.datasource=listOfDoubleIndexTables; I've set the AutoGenerateColumns property to true. But the DGV does not create columns and ofcourse does not display any rows. So i thought, i'll define the rows myself. i set the the AutoGenerateColumns property to false and defined the colums as such: //dataGridDoubleKey.Columns.Add("omniwinRoot", "locatie"); //dataGridDoubleKey.Columns[0].Visible = false; //dataGridDoubleKey.Columns.Add("table", "Table"); //dataGridDoubleKey.Columns.Add("tableKey", "Key"); //dataGridDoubleKey.Columns.Add("tableRecords", "Table records"); //dataGridDoubleKey.Columns[3].Visible = false; //dataGridDoubleKey.Columns.Add("tableUniqueRecords", "Table Unique Records"); //dataGridDoubleKey.Columns[4].Visible = false; //dataGridDoubleKey.Columns.Add("diff", "Number of double keys"); //dataGridDoubleKey.Columns.Add("doubleKey", "Queue double keys"); //dataGridDoubleKey.Columns.Add("noNv

            D 1 Reply Last reply
            0
            • S sharp source

              Ok, i'll start over. The goal of the application is to check visual foxpro tables of an application named omniwin for numerous different problems. The important one for this problem is the analysis of the index key's uniqueness. First the user selects the root of omniwin. After the root is validated this application checks the data tables for double index keys. All the tables wich have to be checked can be found in a table called tableinfo (tableinfo.dbf) and from that table i take the tablename, index field of table, and location of the file in which it is stored. These variables are stored in an instance of ActiveTable, named tableToAnalyze. Next the table is analysed by invoking tableToAnalyze.CheckForDoubleKey(). That method checks number of rows (tableToAnalyze.tableRecords) and number of distinct(id) rows (tableToAnalyze.tableUniqueRecords). If those values do not match the method stores the not distinct keys in a queue (tableToAnalyze.doubleKey) When the table is checked and tableToAnalyze.doubleKey.count() > 1 the instance tableToAnalyse is added to the BindingList listOfDoubleIndexTables. My intention is to display the BindingList listOfDoubleIndexTables in a DGV on the form. Then I can delete rows before starting a fix method because not all problems should be fixed. Problem: I've added a DGV on the form (desinger) and named it: dataGridDoubleKey I've set the DataSource of the DGV to the appropriate datasource: dataGridDoubleKey.datasource=listOfDoubleIndexTables; I've set the AutoGenerateColumns property to true. But the DGV does not create columns and ofcourse does not display any rows. So i thought, i'll define the rows myself. i set the the AutoGenerateColumns property to false and defined the colums as such: //dataGridDoubleKey.Columns.Add("omniwinRoot", "locatie"); //dataGridDoubleKey.Columns[0].Visible = false; //dataGridDoubleKey.Columns.Add("table", "Table"); //dataGridDoubleKey.Columns.Add("tableKey", "Key"); //dataGridDoubleKey.Columns.Add("tableRecords", "Table records"); //dataGridDoubleKey.Columns[3].Visible = false; //dataGridDoubleKey.Columns.Add("tableUniqueRecords", "Table Unique Records"); //dataGridDoubleKey.Columns[4].Visible = false; //dataGridDoubleKey.Columns.Add("diff", "Number of double keys"); //dataGridDoubleKey.Columns.Add("doubleKey", "Queue double keys"); //dataGridDoubleKey.Columns.Add("noNv

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              OK, this was entirely too much code. If I can follow this pile of spaghetti, you're creating a BindingList to hold something, but you never tell the compiler what. BindingList wants to know what kind of type it's holding, like this:

              BindingList listOfDoubleIndexTables = new BindingList<ActiveTable>();
              

              Also, you may want to rewrite the code in the ActiveTable class to expose public data as properties and not public fields. -- modified at 19:20 Tuesday 29th May, 2007

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              S 1 Reply Last reply
              0
              • D Dave Kreskowiak

                OK, this was entirely too much code. If I can follow this pile of spaghetti, you're creating a BindingList to hold something, but you never tell the compiler what. BindingList wants to know what kind of type it's holding, like this:

                BindingList listOfDoubleIndexTables = new BindingList<ActiveTable>();
                

                Also, you may want to rewrite the code in the ActiveTable class to expose public data as properties and not public fields. -- modified at 19:20 Tuesday 29th May, 2007

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                S Offline
                S Offline
                sharp source
                wrote on last edited by
                #7

                that's already in there: public partial class FormAlgemeen : Form { BindingList listOfDoubleIndexTables = new BindingList(); Good point about my modifiers though, i'll rewrite and add some accessor methods later.

                D 1 Reply Last reply
                0
                • S sharp source

                  that's already in there: public partial class FormAlgemeen : Form { BindingList listOfDoubleIndexTables = new BindingList(); Good point about my modifiers though, i'll rewrite and add some accessor methods later.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Whooops! Go look at my previous post again.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  S 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Whooops! Go look at my previous post again.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    S Offline
                    S Offline
                    sharp source
                    wrote on last edited by
                    #9

                    wel, defining properties did the trick. Thanks a lot for your time, and patience ;)

                    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