How do I initialize the checkbox column?
-
I have inserted a datagridviewcheckboxcolumn. But the values of those the checkbox cells are all set to null by default. How do I change them all to "false" which is unchecked?
-
I have inserted a datagridviewcheckboxcolumn. But the values of those the checkbox cells are all set to null by default. How do I change them all to "false" which is unchecked?
Hello Is your DataGridView databound?? In this case you could just use this line of code to return false to the datasource when the user leaves the value null: dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false; If you still want to initialize the values of the cells, I remember something about default values in DatagridView, but i don't seem to recall it at the moment.. What I can think of now is to handle the RowsAdded and initialize the new cells value to false.
Regards:rose:
-
Hello Is your DataGridView databound?? In this case you could just use this line of code to return false to the datasource when the user leaves the value null: dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false; If you still want to initialize the values of the cells, I remember something about default values in DatagridView, but i don't seem to recall it at the moment.. What I can think of now is to handle the RowsAdded and initialize the new cells value to false.
Regards:rose:
Hi I have set the datagridview.datasource to the defaultview of a datatable. Is it databound then? The thing is that the checkbox column is inserted to the datagridview with null values by default. The idea is to let the user to check for export. Cos the unchecked boxes are of null values, I've got an error when the null value is accessed.
-
Hi I have set the datagridview.datasource to the defaultview of a datatable. Is it databound then? The thing is that the checkbox column is inserted to the datagridview with null values by default. The idea is to let the user to check for export. Cos the unchecked boxes are of null values, I've got an error when the null value is accessed.
Hello I provided you with two possible solutions in my last post. Are they not suitable?? 1- You could ignore the null value and return false to the datasource. This should eleminate the error:
dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false;
2-Otherwise you could handle the RowsAdded event and set the value of your column for each new row to false
Regards:rose:
-
Hello I provided you with two possible solutions in my last post. Are they not suitable?? 1- You could ignore the null value and return false to the datasource. This should eleminate the error:
dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false;
2-Otherwise you could handle the RowsAdded event and set the value of your column for each new row to false
Regards:rose:
Hi I've tried both but they don't seem to work. It could be that the datagridview is not databound??? For the 2nd solution, it seemed to work initially, but I don't know why the value switched back to null again. I have made the datagridview a global variable, so nothing should have changed the value back. Now I don't know what to do.
-
Hi I've tried both but they don't seem to work. It could be that the datagridview is not databound??? For the 2nd solution, it seemed to work initially, but I don't know why the value switched back to null again. I have made the datagridview a global variable, so nothing should have changed the value back. Now I don't know what to do.
Hello
printscreen12345 wrote:
I don't know why the value switched back to null again.
What??!!:wtf: What do you mean switched back again?!! Are you sure you did initialize them to false?? Also, how do you populate your DataGridView if it's not databound?
Regards:rose:
-
Hello
printscreen12345 wrote:
I don't know why the value switched back to null again.
What??!!:wtf: What do you mean switched back again?!! Are you sure you did initialize them to false?? Also, how do you populate your DataGridView if it's not databound?
Regards:rose:
Hi Yes, I did initialise them to false in the "try" block and they switched back to null in the "finally" block. I'm not sure if the DataGridView is databound or not. As mentioned in my earlier messsage, I have set dataGridView1.DataSource to a defaultView of a datatable. Is this databound??
-
Hi Yes, I did initialise them to false in the "try" block and they switched back to null in the "finally" block. I'm not sure if the DataGridView is databound or not. As mentioned in my earlier messsage, I have set dataGridView1.DataSource to a defaultView of a datatable. Is this databound??
Hello Yes this is databound, as long as your DataGridView is populated automatically via the view. now let's work this out step by step.. 1-Does your
try
throws an exception?? I mean do you catch anything in thecatch
block?? 2- After you change the value to false, make a break point and watch the value of the last row to be changed.Regards:rose:
-
Hello Yes this is databound, as long as your DataGridView is populated automatically via the view. now let's work this out step by step.. 1-Does your
try
throws an exception?? I mean do you catch anything in thecatch
block?? 2- After you change the value to false, make a break point and watch the value of the last row to be changed.Regards:rose:
Hi, There is no exception thrown at all. It goes straight into the finally block from the last line of code in the try block. I set a break point at the last line of code in the try block and watched the value of the 1st 10 rows of the checkboxcolumn. They were all set to false. But when it stepped into the next line of code (which is the "}" of the try block), they all turned back to null value. This means, it is at the end of the try block that they were switched back. I just realised one thing. The datagridview is displayed when I press a search button. It is very strange that the false values are all switched back to null only the first time when the search button is pressed. They all remained set to false the second time onwards. Actually it has the same kind of problem with the row numbers display - it will never display the row numbers for the first time but it will from the 2nd time onward. Strange?!! Thanks -- modified at 21:12 Tuesday 29th August, 2006
-
Hi, There is no exception thrown at all. It goes straight into the finally block from the last line of code in the try block. I set a break point at the last line of code in the try block and watched the value of the 1st 10 rows of the checkboxcolumn. They were all set to false. But when it stepped into the next line of code (which is the "}" of the try block), they all turned back to null value. This means, it is at the end of the try block that they were switched back. I just realised one thing. The datagridview is displayed when I press a search button. It is very strange that the false values are all switched back to null only the first time when the search button is pressed. They all remained set to false the second time onwards. Actually it has the same kind of problem with the row numbers display - it will never display the row numbers for the first time but it will from the 2nd time onward. Strange?!! Thanks -- modified at 21:12 Tuesday 29th August, 2006
Hello
printscreen12345 wrote:
Strange?!!
Well, errors like these in Visual Studio are what keeps Borland on business;P Anyway, My last question would be: Do you put the false value directly into the cells, or do you put some sort of a local reference field in the try block to hold it?? If you put it in a local field it will turn to null once the block is finished, otherwise really... I'm out of guesses.
printscreen12345 wrote:
it is at the end of the try block that they were switched back.
I guess I'd pass out if I see something like that while debugging??:-D
Regards:rose: