We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding to sql_variant type not working

I have a GridGroupingControl bound to a DataTable. The DataTable is created by using a view in the SQL Server database. One DataColumn is of datatype System.Object, which I guess is what the is created when my database table is of sql_variant type. The problem is when I go to update the field in the GroupingGrid. It blanks out my value when I tab or move to a new cell. The value it puts in the Record is DBNull. I put an AllowDBNull = false on my datacolumn and I received a messagebox with an errorprovider in my column that said SaveRecord: column does not allow nulls when I tried to change the record. I was trying to figure out where an exception might be thrown, and I guess it is thrown within the GroupingGridControl. In order to determine if it was indeed the sql_variant type, I changed the column to numeric and I was able to update the column in the grouping grid without a problem.

7 Replies

AD Administrator Syncfusion Team May 23, 2006 06:49 AM UTC

Hi Martin, Could try this code to resolve this issue. Here is a code snippet. //Form Load event. GridTextBoxCellRenderer cr = this.gridGroupingControl1.TableControl.CellRenderers["TextBox"] as GridTextBoxCellRenderer; if(cr != null) { cr.TextBox.TextChanged +=new EventHandler(TextBox_TextChanged); } private void TextBox_TextChanged(object sender, EventArgs e) { GridOriginalTextBoxControl t = sender as GridOriginalTextBoxControl; GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell; if(cc.ColIndex == 2) { cc.Renderer.ControlValue = (object)t.Text; //cc.ConfirmChanges(true); //If it is not working, you can use this confirmChanges(). } } Please let me know if this helps. Best Regards, Haneef


MN Martin Nitschke May 23, 2006 06:50 PM UTC

It works, except for one problem. I do not know the column index, but I know the column header. How can I find the value of the column header?


MN Martin Nitschke May 23, 2006 07:48 PM UTC

I found it. This does not work: //cc.ConfirmChanges(true); //If it is not working, you can use this confirmChanges(). here is the code to get the header text: GridTableDescriptor gtd = stationTable.TableControl.TableDescriptor; string columnName = gtd.VisibleColumns[cc.ColIndex - 1].GetName();


MN Martin Nitschke May 26, 2006 07:53 PM UTC

I have another problem. The Text_Changed event does not fire if I currently have a value the same number or characters long when I hit the down arrow. For example, I have values of all 2''s in my column. I click the first one, press 3, then the down arrow. As I continue entering 3 and pressing the down arrow the text_changed never fires. however, if I were to replace a 2 with 33, since the length changed, it does fire.


AD Administrator Syncfusion Team May 29, 2006 04:40 AM UTC

Hi Martin, Sorry for the inconvenience caused. I have tested this issue by creating a sample in v.4.1.0.50/4.1.0.62 and then again tested by upgrading to V4.2. I was not able to reproduce the issue.Maybe I am not following the steps that you are doing. Attached sample working fine here. If you can send us a sample that does not work, we can try to debug it here. Here is a sample. http://www.syncfusion.com/Support/user/uploads/SQL_Varient_dd51d03e.zip Could you please run this at your end and let me know how it goes? Thanks for your co-operation. Regards, Haneef Note: Before run the sample, you need to change the connection string and create a table with two column.


MN Martin Nitschke May 30, 2006 05:53 PM UTC

I ran the test on my end. I have the .63 version. I created a table in the NW database. I inserted row1, 1; row2, 2; row3, 3; etc for data values. In order to reproduce the error. Click into the first column with the value row1. Press the tab key. You will move to column 2, where the current value is 1. Without doing anything else, type in the value 2, then press the down arrow key. No text changed event is written to the console (per your code) and the value of the cell is blank. You can continue typing in single values and the same result will be for all the columns. However, if you were to type in 33 or 44, the Text Changed event would fire and write to the Console.


AD Administrator Syncfusion Team June 2, 2006 06:13 AM UTC

Hi Martin, I regret really for the inconvenience caused. I was able to see the mentioned issue here. I have tested the modified sample in 4.1 and then again tested by upgrading to 4.2 which is working fine. Please find the modified code/sample below. private void gridGroupingControl1_TableControlCurrentCellChanged(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlEventArgs e) { CovertCellValueToObject(); } public void CovertCellValueToObject() { GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell; GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer; GridOriginalTextBoxControl t = cr.TextBox as GridOriginalTextBoxControl; if(cc.ColIndex == 2) { cc.Renderer.ControlValue = (object)t.Text; cc.ConfirmChanges(true); } Console.WriteLine("Fire"); } private void gridGroupingControl1_TableControlCurrentCellMoving(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellMovingEventArgs e) { GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell; if(cc.MoveFromColIndex == 2) { CovertCellValueToObject(); } } Here is a modified sample. http://www.syncfusion.com/Support/user/uploads/SQL_Varient_c7306398.zip Please let me know if this helps. Regards, Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon