Home > Net >  WPF custom column in the DataGrid TextBox in editing the contents of how to get inside the cell
WPF custom column in the DataGrid TextBox in editing the contents of how to get inside the cell

Time:09-28



I want to do a thing, in the selected row has a text box is my custom to go up, not found out from a database, I want to have selected these two data ID added to the database, at the same time, the value of the corresponding text box together add a table to the other, is each text box corresponding value, you have what way, it is best to have a code, I am a rookie, don't know theory out

Xaml code:




CodePudding user response:

1. Use ObservableCollection As the data source binding DataGrid list, so that a new data processing,
2. The Mode=TwoWay, so we can get to the front of the modified data,
Examples are as follows:
XAML:








CS background:
Public partial class MainWindow: Window
{
MainWindowViewModel vm=new MainWindowViewModel ();

Public MainWindow ()
{
InitializeComponent ();

Enclosing DataContext=vm;
}

Private void BtnTest_Click (object sender, RoutedEventArgs e)
{
Foreach (var item in the vm. The DataList)
{
//get data
}
}
}

Public class MainWindowViewModel
{
Public ObservableCollection DataList {get; The set; }

Public MainWindowViewModel ()
{
The DataList=new ObservableCollection (a);
DataList. Add (new CTestInfo {an IsSelected=true, TestCaseInfo="option 1", ResShare=25.7});
DataList. Add (new CTestInfo {an IsSelected=false, TestCaseInfo="option 2", ResShare=36.9});
}
}

Public class CTestInfo
{
Public bool an IsSelected {get; The set; }
Public string TestCaseInfo {get; The set; }
Public double ResShare {get; The set; }
}

CodePudding user response:

The text box is a custom I, is to write their own data, not found out from a database, so, this does not apply

CodePudding user response:

Do you know about the WPF data binding can be single, can also be a two-way street; Not to say that only found out from a database can be binding, in fact, in most cases the ViewModel is not found out directly from the database

CodePudding user response:

Use your code, no, there is a better way?

CodePudding user response:

Quote: refer to the third floor Eason0807 response:

I used your method, error directly

CodePudding user response:

refer to the second floor weixin_44549211 response:
I of the text box is a custom, is to write their own data, not found out from a database, so, this does not apply to

Can individual binding Mode=OneWayToSource
  •  Tags:  
  • C#
  • Related