If you're using the XtraGrid GridControl, you want to deal more with the GridView, which is the editor contained within the GridControl.
Typically, you'll bind your data to the GridControl's DataSource Property, but most of the other events and properties that you'll want to use for user experience will be related to the GridView itself.
Some of the handier methods and properties you get with the GridView are FocusedRowHandle
, FocusedColumn
, GetFocusedRow()
, etc.
So, when you register your click event for that button, inside that method, store a reference to the gridview, i.e.
private void SomeButtonClick(object sender, EventArgs e)
{
var gridView = this.whateverYourGridViewIsNamedGridView;
//Now, you can access the methods and properties of the gridView...
//Say you want to obtain the focused row's handle
var rowHandle = gridView.FocusedRowHandle;
//Or, in your case, if you want to iterate through the rows or columns...
for(GridColumn column in gridView.Columns)
{
if(condition)
{
//Do something
}
}
}
Based on your scenario, I would suggest that you again open the Designer. On the bottom left, click In-Place Editor Repository. You should see your CheckEdit
here. If you select the CheckEdit
, you should be able to click the little lightning bolt and access the editor's events. You want to register with the CheckStateChanged
event or the CheckedChanged
event, which will fire any time any of the editor's check state's are changed.
From here, I would add a bool to your domain object or a viewmodel to decorate that domainobject with bool on it for isChecked
. This way, when the check event fires, you can handle setting this bool... for example:
private void CheckEventFiring(object sender, EventArgs e)
{
//Get the currently focused row and cast it to your object
//This will expose all the properties, including the aforementioned boolean value
var currentRow = gridView.GetFocusedRow() as YourDomainObject;
//Based on checked state...
currentRow.IsChecked = //Checked or Unchecked
}
Now that you've set this, when you click the button, you can just get all the items from your grid control's data source that "are checked" by doing something like...
var dataSource = gridControl.DataSource as List<YourDomainObject>().Where(x => x.IsChecked);
Now you only have the data from the rows where the items are checked. When check state is unchecked, the bool on the object should be false, when checked it should be true.
Let me know if this makes sense or not. Dev Express has a small learning curve, but once you get it, it's pretty easy.