BindingList and DataGridView question. [modified]
-
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 -
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, 2007sharp 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 thisActiveTable
class have to do with anything?A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
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 thisActiveTable
class have to do with anything?A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Sorry, 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
-
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
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 -
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, 2007Ok, 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
-
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
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 -
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, 2007that'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. -
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.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 -
Whooops! Go look at my previous post again.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007wel, defining properties did the trick. Thanks a lot for your time, and patience ;)