datagridtextcolumn

WPF/DataGrid: Binding to different properties for displaying and editing

蓝咒 提交于 2021-01-28 00:51:51
问题 I have an object that contains eg a string property like "10; 20; 30". I have also a get property that splits the string, converts each part to a double and sums them up. Thus I have "10; 20; 30" and 60.0 (as double). Now the question is. Is there a way to display the 60.0 (as double) in a TextColumn, but when going to edit mode editing the string "10; 20; 30"? So that I can bind to one property for displaying and to bind to another property for editing? 回答1: You can achieve this with your

WPF Change datagrid cell background color using a converter

若如初见. 提交于 2020-01-30 03:47:54
问题 I have an WPF datagrid. There are two columns of type datetime which I need to compare and according to the compare result, I set a cell background color for the two cells in the current column and row. I do this for each datagrid row. In order to do this I use a converter. <my:DataGridTextColumn Binding="{Binding Path=Date1, StringFormat=\{0:dd/MM/yyyy\}}" Header="Date"> <my:DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="Background"> <Setter.Value>

WPF Change datagrid cell background color using a converter

北慕城南 提交于 2020-01-30 03:47:13
问题 I have an WPF datagrid. There are two columns of type datetime which I need to compare and according to the compare result, I set a cell background color for the two cells in the current column and row. I do this for each datagrid row. In order to do this I use a converter. <my:DataGridTextColumn Binding="{Binding Path=Date1, StringFormat=\{0:dd/MM/yyyy\}}" Header="Date"> <my:DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="Background"> <Setter.Value>

how to set binding stringformat to all DataGridTextColumn controls?

筅森魡賤 提交于 2020-01-14 15:56:30
问题 This is one of my DataGridTextColumn controls looks like : <DataGridTextColumn x:Name="contractStartDateColumn" Header="Start Date" Binding="{Binding Path=StartDate, StringFormat={}\{0:dd/MM/yyyy\}}" /> Then how can I set StringFormat={}{0:dd/MM/yyyy} to all of DataGridTextColumn controls instead of setting every single one ? 回答1: You can create custom binding class that sets StringFormat and use it to bind values: public class CustomBinding : Binding { public CustomBinding(string path) :

WPF DataGridTextColumn Can't type point for float data

大憨熊 提交于 2019-12-23 12:28:36
问题 I had a WPF DataGrid and use DataGridTextColumn Binding to a Collection. The items in Collection had some float property. When my program launched, I modify the value of float property in DataGrid, if I type a integer value, it works well. But if I type char . for a float value, char . can't be typed. I had to type all the numbers first, and then jump to the . position to type char . to finish my input. So how can I type . in my situation? Thanks. 回答1: Also met the same problem. For my case,

WPF DataGridTextColumn binding doesn't accept decimals

偶尔善良 提交于 2019-12-18 07:46:06
问题 I don't understand what the problem could be. The binding is on a Decimal property. Here is the XAML: <DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged} Width="*"/> I literally cannot type the '.' character. Why would it stop me from typing that character and how do I tell it to let me do so. I tried doing a string format like this: <DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger

WPF DataGridColumnWidth doesn't work well when PrintVisual

倖福魔咒の 提交于 2019-12-08 04:00:30
问题 I have a ucReceipt.xml that looks fine in design mode or even it looks good while Opening the window http://prntscr.com/5xl11h: <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Receipt.ReceiptItems}" IsReadOnly="True" CanUserSortColumns="False" CanUserResizeColumns="False" RowHeaderWidth="0" Grid.Row="4"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding ItemNo}" Header="No" Width="0.5*" /> <DataGridTextColumn Binding="{Binding cloth.Name}" Header="Description" Width="*" />

Masking password column in datagridview

大憨熊 提交于 2019-12-02 22:20:52
问题 I'm having problem with masking the password column. The code below works, but it doesnt work the way I want. While editing it do mask the password but when I am done and continue to the next datagridviewcell password becomes visible. private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if ( dataGridView1.CurrentCell.ColumnIndex == 5 || dataGridView1.CurrentCell.ColumnIndex == 10)//select target column { TextBox textBox = e.Control as

Masking password column in datagridview

萝らか妹 提交于 2019-12-02 08:02:38
I'm having problem with masking the password column. The code below works, but it doesnt work the way I want. While editing it do mask the password but when I am done and continue to the next datagridviewcell password becomes visible. private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if ( dataGridView1.CurrentCell.ColumnIndex == 5 || dataGridView1.CurrentCell.ColumnIndex == 10)//select target column { TextBox textBox = e.Control as TextBox; if (textBox != null) { textBox.UseSystemPasswordChar = true; } } var txtBox = e.Control as

How do I Add a Tooltip To a DataGridTextColumn

佐手、 提交于 2019-11-30 07:43:03
问题 I'm using WPFtoolkit DataGrid ,I have to wrap text in a DataGridTextColumn or I have to add a ToolTip to the text column. I have searched the net but i couldn't get a proper solution. Expecting your valuable suggestions... 回答1: Yes, you can add tooltip text to DataGridTextColumn - just stylize it <DataGridTextColumn Header="ScreenName" Binding="{Binding ScreenName}" > <DataGridTextColumn.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="ToolTip" Value="{Binding Name}" /> </Style>