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

CheckBox in a column

Hello I'm evaluating Essential Grid, I've made an easy test to insert a checkbox in a column and doesn't work properly. I have the next class to populate data in the Bound Grid. class datos { public datos (int dato1, bool dato2, string dato3, bool dato4) { Dato1 = dato1; Dato2 = dato2; Dato3 = dato3; Dato4 = dato4; } int m_dato1; bool m_dato2; string m_dato3; bool m_dato4; public int Dato1 { set { m_dato1 = value;} get { return m_dato1; } } public bool Dato2 { set { m_dato2 = value;} get { return m_dato2; } } public string Dato3 { set { m_dato3 = value;} get { return m_dato3; } } public bool Dato4 { set { m_dato4 = value;} get { return m_dato4; } } } ArrayList al = new ArrayList(); for (int i=0; i
6 Replies

CB Clay Burch Syncfusion Team August 26, 2002 08:24 PM UTC

Jose, Instead of trying to set the "CheckBox" in the ColStyles array, use the GridBoundColumns to specify the CellType. Since you did not explicitly add in bound columns, you can access the internal bound columns to use those to format the columns. gridDataBoundGrid1.Binder.InternalColumns[1].StyleInfo.CellType = "CheckBox"; //col 2 gridDataBoundGrid1.Binder.InternalColumns[3].StyleInfo.CellType = "CheckBox"; //col 4


JB Jose Bonnin August 27, 2002 04:49 AM UTC

First of all thank you for your answer. I don't know where is the problem but if I type this it doesn't works. class datos { public datos (int dato1, bool dato2, string dato3, bool dato4) { Dato1 = dato1; Dato2 = dato2; Dato3 = dato3; Dato4 = dato4; } int m_dato1; bool m_dato2; string m_dato3; bool m_dato4; public int Dato1 { set { m_dato1 = value;} get { return m_dato1; } } public bool Dato2 { set { m_dato2 = value;} get { return m_dato2; } } public string Dato3 { set { m_dato3 = value;} get { return m_dato3; } } public bool Dato4 { set { m_dato4 = value;} get { return m_dato4; } } } ... ArrayList al = new ArrayList(); for (int i=0; i

JB Jose Bonnin August 27, 2002 06:13 AM UTC

Finally I saw that that code put the checkbox in the column, but not ever, sometimes it works after click or set order in a column header others when by code I try to modify some values. It seems as if the grid was not repainting the components, I've tried to force an Update() without success, any idea?


CB Clay Burch Syncfusion Team August 27, 2002 07:05 AM UTC

Jose, Using an arraylist (implements IList) as a datasource does not have the same built-in mechanisms for reflecting changes between the datasource and the grid that for example using a DataTable (implements IListSource) does. This means you have to either implement the extra interfaces, or directly handle things in your code. For example, if you programatically change your arraylist, and want to see the changes in the grid, then you could force a refresh on the bindingcontext from code. CurrencyManager cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource]; cm.Refresh(); To be updatable, the datasource has to implement IBindingList, and an arbitary ArrayList does not do this. We will look into add some type of IBindingList support for allowing an ArrayList to be updatable. However, it would be simple to use the GridControl control in a virtual mode and bind your arraylist through handling QueryCellInfo. Take a look at the Virtual Grid Tutorial which steps you through the 3 events you would need to handle. Then to make the arraylist updatable, you handle SaveCellInfo to move the edited values back into your array list. Even though you are handling 4 events, it only requires a couple of lines of code in each event. It is straight forward. In one event, you provide the colcount, in another you provide the rowcount, in another you get the value, and in the last you set the value. This is straight-forward way of binding arbitrary datasources to a grid. The only requirement of the datasource is that its has to be able to provide a value for cell given its row and column. Thats it. And if you want teh datasource updatable, it has to be able to accept a changed value for a a specified row and column. If you want to attach a file, we can take a look at what you are trying to do. But I suspect that the problem has to do with the missing interfaces necessary to make a IList updatable. -Clay


JB Jose Bonnin August 27, 2002 12:13 PM UTC

Thank you again for your answer. That I want to do is much more easy than all this, I only want to show the checkbox inside the row, and the code that I've tested doesn't work because the grid doesn't paint it ever, only when I make a mouseover, trying to change something, ... I send a litle project to test it.


CB Clay Burch Syncfusion Team August 28, 2002 08:08 AM UTC

Jose, In the current version, the StyleInfo member of the internal GridBoundColumn is not being used consistently to determined the resulting style of each cell in the column. This will be corrected. In the meantime, I was able to get you code to work by setting the checkbox celltype in both the internal gridboundcolumn and in the ColStyles member of the Model. Here is code that made your checkboxes appear. I added the Begin & end update to avoid duplicate painting. gridDataBoundGrid1.BeginUpdate(); gridDataBoundGrid1.DataSource = al; gridDataBoundGrid1.TableStyle.CheckBoxOptions.CheckedValue = Boolean.TrueString; gridDataBoundGrid1.TableStyle.CheckBoxOptions.UncheckedValue = Boolean.FalseString; gridDataBoundGrid1.Binder.InternalColumns[1].StyleInfo.CellType = "CheckBox"; //col 2 gridDataBoundGrid1.Binder.InternalColumns[3].StyleInfo.CellType = "CheckBox"; //col 4 gridDataBoundGrid1.Model.ColStyles[2].CellType = "CheckBox"; gridDataBoundGrid1.Model.ColStyles[4].CellType = "CheckBox"; gridDataBoundGrid1.EndUpdate(true);

Loader.
Live Chat Icon For mobile
Up arrow icon