.MasterGridViewTemplate.LoadFrom(command.ExecuteReader())
In the old VB6 ListView one can set the "Checkboxes" property to True and have checkboxes appear.Is there a similar property in the RadGridView?
The checkboxes would not be bound to the database, but only used as an alternative way to select rows (.MultiSelect = True).
(With HotTracking and AlternateColors enabled, it can sometimes be a bit hard to easily see which rows are selected.)
Finn
5 Answers, 1 is accepted
There is no out-of-the-box property that could enable/disable checkboxes for row selection. I think however you could easily implement this by adding an unbound GridViewCheckBoxColumn. This column could be used to hold true/false value for every row depending if it is selected or not by the user. Later, to find which rows are checked you could iterate through the DataAccessComponent.Rows collection for example like this:
List<GridViewRowInfo> GetCheckedRows(RadGridView grid) |
{ |
List<GridViewRowInfo> checkedRows = new List<GridViewRowInfo>(); |
foreach (GridViewRowInfo row in grid.Rows) |
{ |
if ((bool)row.Cells["Bool"].Value) |
{ |
checkedRows.Add(row); |
} |
} |
return checkedRows; |
} |
Also, if you like you could handle RadGridView.ValueChanged event and set GridViewRowInfo.IsSelected property of the corresponding row which has been just selected. You could use something like this:
void radGridView1_ValueChanged(object sender, EventArgs e) |
{ |
GridDataCellElement cell = sender as GridDataCellElement; |
if (cell != null && ((GridViewDataColumn)cell.ColumnInfo).FieldName == "Bool") |
{ |
cell.RowInfo.IsSelected = (bool)cell.Value; |
} |
} |
Please, try this approach and tell us if it works fine for you. I'm looking forward for your response!
Greetings,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'll try this as soon as I figure out how to add an unbound checkbox column, and when I figure out how to change the C# code you gave into VB .NET.
I'm new to VB .NET and C# is way above my head.
Finn
I've been desperately trying to do the same thing in adding a checkbox for user selection purposes. Inspired by this thread, I tried once again tonight. My attempt is a little different than suggested but I'm close... oh so close. Still not quite there. There appears to be a bit of an issue I cannot get around. To recreate what I've done:
- Add a grid and bind it to a binding source.
- Add an unbound checkbox column as the first column.
- All columns from the binding source are read only. The checkbox is not read only.
- AllowEditRow is set to True.
- I added a button to the form to simply loop through the rows to test this. Behind that button is the following "test" code:
PartListRadGridView.EndEdit()
For Each row As GridViewRowInfo In Me.PartListRadGridView.Rows
MsgBox(row.Cells(0).Value & row.Cells(2).Value)
Next
Upon checking checkboxes in multiple, discontiguous rows and then hitting the button that runs the code above, the same thing always happens, all rows I've checked return true but if I have not tabbed out of the last row where I checked the checkbox, it gets cleared the minute I run that code. This is actually why I began that chunk of code with an EndEdit. That had worked for me in the past as a way around the user not tabbing out of a field in a row before hitting a button that "did something" with their changes. It does not, however, seem to be doing me any good in this instance. If I don't tab out of that row, the checkbox gets cleared. Period. Why? A user, by nature, will not tab out of a row after they've checked rows they want to select nor after they've changed any other type of data in a row, for that matter. How do I force the grid to tab out programatically before processing the rows? I'm soooo close to getting this to finally work!!
As obviously this appears to be a very common scenario, I wrote it as a Knowledge Base article.
Finn, please take a look at the article - there are sample applications both on VB and C#. You could get more info from our documentation and also research the grid examples ("Column Types", "Unbound Mode", etc.).
Judy, I think that the problem bothering you has been already fixed and does not exist in the latest version - Q2 2008. By design, when grid loses the focus and there are pending changes, it should save them. That's why you don't need to call explicitly RadGridView.EndEdit(). Please make sure you're using the latest version and if the problem persist I would ask you to prepare us a sample application that reproduces the problem.
If you have any additional questions, we'll be glad to help you further.
Sincerely yours,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.