-
DataGrid Hell
I now believe I am back at the bottom of the learning curve and boy what a long way to go, if I am spending so much time getting to grips with a "simple" datagrid .
- .net programmers will be a rare breed - C++ was easier to learn
Any help on the three problems below would really be appreciated.
1.) - Boolean Values in the datagrid
I have a DataGridBoolColumn in the Datagrid. The checkbox inserted in the column gives me three states True,False and Null
How does one stop this giving a null state - and why on this good earth would you want a bool to be in a null state. It would definitely not be a boolean by definition.
2.) - Databinding
I can edit the grid but the last item editted is not updated in the bound datatable. It appears that if the cell still has focus and one then clicks on a button (not part of the grid) to update - the cell with the focus is not updated. Updating obviously occurs on the loss of the focus. Is there a update type of methods that force updating of the binding.
3.) - Adding extra row.
I want the user to be able to edit the grid but not add new records. If I set the readonly property to False, the datagrid decides - without my consent - to add another row for possible addittions. How do I prevent this.
-
I found the answer to item 2 - Adding new row
With grid
.DataSource = dt
dt.DefaultView.AllowNew = False
End With
Where dt is a datatable from the dataset.
-
Okay we are moving up the learning curve.
Answer to question 2 - Databinding
dt.AcceptChanges() 'Accept the changes input from the grid
Before submitting the dataset one should AcceptChanges
Note: dt is a datatable in the dataset
-
Thanks for the post it actually answers a few of my problems also. The datagrid seems extremely arkward to use. Would be very interested if you get a solution to the first probem you mentioned, i.e. the states of the checkbox.
I also have the probem where the user clicks on the checkbox and expects the checkbox to change state, this is not what happens, the first click only selects the row, you need to click again to actually change the status of the checkbox. So essentially to change the state of a checkbox you need to click it twice - do you know of a way of changing this behaviour???
-
Finally the answer to the tristate problem: - Problem 1
You should use ColumnStyle to change its AllowNull property to false.
-
Just a little reason why you would want a boolean value to be null...
Let's say you have a column in a table that records a users response. Now if for some reason the person never gave a response (like a question was never asked to him/her), then you don't want to put a definate Yes or a definate No. This is because you shouldn't assume the answer the person is going to give (it would be bad in a business sense). This would allow you later to do a query to find the people that where never asked this question. Then you can have your telemarketers (boy I hate those people) call and get an accurate answer to the question. You NEVER want false or inacurate data in a database if you can help it.
Anyway, you asked why you would want a null, and there is an example of why you would.
-
Thanks hellswraith,
Yes, I can see that - thanks for the great imformation.
The other reason I thought of was that a database could probably have a null value at times.
Cheers Bryan