TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ray Dean
NA
8
9.2k
WPF - Making a checkbox select rows within a data grid
Dec 4 2020 12:31 PM
Hi All.
New to C# programming, I set myself a challange to build a GUI application. The application populates a datagrid with data from a table. I have a checkbox added to the datagrid column, and what I would like is for the checkbox to be the sole method for selecting items within the datagrid. So if the checkbox is checked 10 times for 10 datagrid items selected, those items are selected from the datagrid. This is what I have so far and I am stuck with the checkbox issue.
As can be seen below, despite selecting server id 7,8 the datagrid row only recognises 3 as its the only one highlighted.
<DataGrid x:Name=
"GridServerList"
CanUserAddRows=
"False"
AlternatingRowBackground=
"Beige"
Grid.Column=
"5"
HorizontalAlignment=
"left"
Height=
"365"
Width=
"625"
AutoGenerateColumns=
"False"
Margin=
"9,159,0,0"
VerticalAlignment=
"Top"
Grid.ColumnSpan=
"8"
SelectedItem=
"{Binding PopulateDataGrid, Mode=TwoWay}"
>
<DataGrid.Columns>
<DataGridCheckBoxColumn x:Name=
"chkSelectedServer"
Binding=
"{Binding IsChecked, Mode=TwoWay}"
Header=
"Choose"
IsReadOnly=
"False"
CanUserSort=
"False"
>
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType=
"CheckBox"
BasedOn=
"{StaticResource {x:Type CheckBox}}"
>
<EventSetter Event=
"Checked"
Handler=
"OnChecked"
/>
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
<DataGridTextColumn Binding=
"{Binding Server_Id}"
Header=
"Server_Id"
IsReadOnly=
"true"
/>
<DataGridTextColumn Binding=
"{Binding Server_Name}"
Header=
"Server_Name"
IsReadOnly=
"true"
/>
</DataGrid.Columns>
</DataGrid>
Within my CS file, I do not have any code relating to the functionality that I require.
Reply
Answers (
2
)
how to get the text of all selected checkbox ?
how to publish winforms app?