Sunday, 15 February 2015

c# - Three-column GridView: one with only text, the other two with checkboxes -


I'm having trouble compelling values ​​in the checkbox and, later, to check the checkbox in gridview. Basically, I have three columns named property, tele, and nick, respectively, and I have a list of row type items. The row has three properties: name (string), tele (boole) and sur (boole). I want to populate the property with all the names (and such a display looks fine, through displaymemberbending), and the other two columns

Code> & lt; UserControl x: class = "WpfApplication2.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com / Winf X / 2006 / Xaml "xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "mc: Ignorable = "D" Datacentext = "{Binding Relative Soros = {Relative Aces Self}}" Margin = "0,0, -8,0"> Grid X: Name = "Live" margin = "0,0, -8.0 "& Gt; Text Box Horizontal Alignment =" Left "Height =" 23 "margin =" 114.99,12.96,0,0 "textwapping =" wrap "text =" default name "vertical alignment =" top "width = "175.01" /> & Lt; Label content = "name:" horizontal A lignment = "left" margin = "10,10,0,0" vertical alignment = "top" /> & Lt; ListView DataContext = "{binding element name = rows}" x: name = "LView" horizontal alignment = "left" height = "159" margin = "0,52,0,0" workbench = "top" width = "2 9 2 "& gt; & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn x: name = "property" width = "100" header = "property" DisplayMemberBinding = "{binding name}" & gt; & Lt; / GridViewColumn & gt; & Lt; GridViewColumn x: name = "tele" width = "100" header = "In tele?" DisplayMemberBinding = "{binding off}" & gt; & Lt; GridViewColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Checkbox X: Name = "Telechoc" Ischaked = "{Binding Source = {Reslevances Teles}}" & gt; & Lt; / Checkbox & gt; & Lt; / DataTemplate & gt; & Lt; /GridViewColumn.CellTemplate> & Lt; / GridViewColumn & gt; & Lt; GridViewColumn x: name = "Surr" Width = "100" header = "In Surr?" DisplayMemberBinding = "{Binding Sur}" & gt; & Lt; GridViewColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Checkbox X: name = "telechoc" ischaked = "{binding source = {relative protection}}" gt; & Lt; / Checkbox & gt; & Lt; / DataTemplate & gt; & Lt; /GridViewColumn.CellTemplate> & Lt; / GridViewColumn & gt; & Lt; / GridView & gt; & Lt; /ListView.View> & Lt; / ListView & gt; & Lt; / Grid & gt;

XAML.CS:

  Public partial class main window: User control [Personal supervision collection & lt; Row & gt; Rows; Public Supervision Collection & lt; Row & gt; Rows {Get Rows of Return; }} Public Main Window () {Rows = New Observation Collection & lt; Line & gt; (); Rows. Add (new line ("item 1", true, false)); Rows. Add (new line ("item 2", true, true)); InitializeComponent (); }}   

}

RAW:

  Public class row: INotifyPropertyChanged {Private string Name_; Private Bull _tail; Private Bull _ Pig; Public string name {get {return _name; } Set {if (_name == value) returns; _name = value; NotifyPropertyChanged ("name"); }} Public Balls Tele {get {return _tel; } Set {if (_tel == value) returns; _tel = value; NotifyPropertyChanged ("oil"); }} Public Bull Sur {get {return_sur; } Set {if (_sur == value) returns; _sur = value; NotifyPropertyChanged ("Sur"); }} Public line (string name, boolean value, value value 2) {name = name; Oil = value; Sur = value 2; } Private Event PropertyChangedEventHandler PropertyChanged; Private Zero NotifyPropertyChanged (String Information) {if (PropertyChanged! = Null) {PropertyChanged (New, PropertyChangedEventArgs (info)); }}}   

}

made some changes to your code And it is working and it is working.

First of all, do not store your rows in the window constructor, after this window is loaded. Unfortunately I could not force the archive in the grid item list , so I did it in Codebahind after filling the collection. And rows archive personal , so you need puplic DataContext = "{Binding ElementName = rows}" was not correct collection named rows

< / P>

and secondly - / Li>

  • Instead of IsChecked = "{binding source = {relative es tele telep}} Use IsChecked = "{Binding Telephone} and Sur

  • No comments:

    Post a Comment