Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Ravenous84 Absent Member.
Absent Member.
3432 views

Get Datagrid items with checkbox collumn selected.

Hello

Currently I have a datagrid with 3 columns, ID - Name - Selected.  The Selected column is a checkbox column. Im triying to fing a way to get all items in the datagrid with the Selected colum checked. I can do this in C# easy  but cant figure it out in visual cobol.

Thanks for the help !

0 Likes
9 Replies
Micro Focus Expert
Micro Focus Expert

RE: Get Datagrid items with checkbox collumn selected.

If you show me the C# code you use I will convert it to COBOL.

0 Likes
Ravenous84 Absent Member.
Absent Member.

RE: Get Datagrid items with checkbox collumn selected.

Something like this.

Just typing out of my head im sure theres some erros.

foreach(GridViewRow row in dgCaregories.Rows)

{

      // Get the Checkbox cell value

}

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Get Datagrid items with checkbox collumn selected.

Something like this:

perform varying row as type GridViewRow thru dgCategories::Rows

    *> Get the Checkbox cell value

end-perform

This is documented in the language comparison chart here:

Look at example for Loops or how to iterate thru a collection

Ravenous84 Absent Member.
Absent Member.

RE: Get Datagrid items with checkbox collumn selected.

i get "System.Windows.Controls.DataGrid' has no member with name 'Rows'

perform varying row as type System.Windows.Controls.DataGridRow thru dgCategory::Rows

   *> Get the Checkbox cell value

end-perform

0 Likes
lanter-edv_ch Outstanding Contributor.
Outstanding Contributor.

RE: Get Datagrid items with checkbox collumn selected.

DataGrid is based on ItemsControl, so use dgCategory::Items.

Why are you not using Binding, which gives you all values in a simple collection with a condition-value for the checkbox?

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Get Datagrid items with checkbox collumn selected.

I only converted your original C# example which must be for a Windows Forms dataGridView control instead of a WPF dataGrid control which is different.

The WPF dataGrid control does not have a Rows property as the error indicates.

What type of application are you creating, WinForms, WPF, ASP.NET?

0 Likes
Ravenous84 Absent Member.
Absent Member.

RE: Get Datagrid items with checkbox collumn selected.

Its WPF. I set the datagrid itemSource to the list of  categories. Then add the column of checkboxes to select wich categories I want to pick. So far so good. The problem is that i cant find how to read the categories with checked box.

the category object is just CategoryID and Category Name.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Get Datagrid items with checkbox collumn selected.

Here is an example which uses 2way binding on an observable collection. After the checks are done and a button is clicked it will read back thru the collection and display the checked items in a separate listbox.

0 Likes
Ravenous84 Absent Member.
Absent Member.

RE: Get Datagrid items with checkbox collumn selected.

Thanks ! and sorry for not being clear.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.