Hi,
i am using the GDBG with columns bound to a data set and an additional unbound checkbox column.
To get along with the unbound column I used the example from the Knowledgebase. What I tried to
accomplish additionally is to throw an event every time a checkbox state changes and be able to get
all checked rows in the grid afterwards.
My first problem is that the display of the checkbox gets messed up, as soon as I modify Model_SaveCellInfo()
to execute some additional code which basically gets all selected rows in the grid. Additionally, the additional code seems
to stop executing (I can''t step forward with the debugger) for reasons I do not know. I expect this to be a timing problem
maybe linked to the QueryCellInfo event but I can''t really say. Maybe you can help me with my problem?
Regards,
Alex
AD
Administrator
Syncfusion Team
May 30, 2006 04:29 AM UTC
Hi Alexander,
Try this code to get all checked checkbox record in a grid using CurrentCellChanged event. Here is a code snippet in C#.Net.
private void gridDataBoundGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
Console.WriteLine("Checked CheckBox Details.....");
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell as GridCurrentCell;
int ColIndex = grid.Binder.NameToColIndex("CheckBox");
for(int i = 1 ;i< grid.Model.RowCount;i++)
{
object obj = grid.Model[i, ColIndex].CellValue;
if(obj != null && obj.ToString() != string.Empty && obj.ToString() == "True")
Console.WriteLine(" Check CheckBox RowIndex :" + i + " Products CellValue -> " + grid.Model[i, 1].CellValue);
}
}
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/UnboundCheckBoxColumn_CS_ecb46030.zip
Let me know if you need any further assistance.
Regards,
Haneef
AL
Alex
May 30, 2006 06:00 AM UTC
Hi Haneef,
thank you very much! The code works perfectly :-)
Regards,
Alexander
AL
Alex
May 30, 2006 12:23 PM UTC
Hi Haneef,
Unfortunately, my last post came a bit early altough it seemed my problem was solved by the solution you provided. Basically, the timing problem still exists but with your suggested code in the CurrentCellChanged event handler the time frame for my own code to execute has extended. The more operations are executed in the event handler, the higher is the possibilty that the code stops executing randomly.
Regards,
Alex
AD
Administrator
Syncfusion Team
May 30, 2006 01:35 PM UTC
Hi Alex,
You need to store the checked checkbox record into ArrayList in a grid''s Model_SaveCellInfo event and retrive this information from any event(currentCellchanged Event). Here is a code snippet in C#
ArrayList checkedlist = new ArrayList();
private void Model_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
GridModel model = this.gridDataBoundGrid1.Model;
int ColIndex = this.gridDataBoundGrid1.Model.NameToColIndex("CheckBox");
if(e.RowIndex > 0 && e.ColIndex == ColIndex)
{
int keyColIndex = model.NameToColIndex("Product_ID");
string key = model[e.RowIndex, keyColIndex].Text;
if (key != null)
{
CheckBoxValues[key] = e.Style.CellValue;
if(checkedlist.Contains(key) )
{
if(! (e.Style.CellValue.ToString() == "True" ) )
checkedlist.Remove(key);
}
else
checkedlist.Add(key);
}
}
}
}
//Get the infomation from Button click/any event you want.
Console.WriteLine("Checked CheckBox Details.....");
for(int i = 0 ; i< checkedlist.Count ;i++)
{
Console.WriteLine(checkedlist[i]);
}
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/UnboundCheckBoxColumn_CS_fe25efea.zip
Let me know if you need any further assistance.
Regards,
Haneef