用逗号输入文本到datagrid wpf

时间:2017-02-08 12:35:47

标签: c# wpf visual-studio data-binding datagrid

我正在使用数据网格来整理客户信息。这包括一个注释部分,其中不可避免地包括逗号。保存为CSV时,我可以解决这个问题,但数据网格会一直分割我的文本,并在看到逗号时将所有内容移动。

            string firstName = txtFirstName.Text;
        string colour = cbxNature.SelectedItem.ToString();

        BriefLine = txtBriefDetails.Text.Split(',');
        newBrief = string.Join("\\,", BriefLine);
        Debug.Print("new brief_" + newBrief);


        Customer customer = new Customer
        {
            Date = txtDate.Text,
            Name = txtFirstName.Text,
            Nature = cbxNature.Text,

            Brief_Details = newBrief,
            Follow_up_Date = txtfollowupdate.Text,
            Notes = txtNotes.Text,
            Contact_Details = ContactDetails.Text,
            Taken_By = txtTakenBy.Text
        };

        // Add the new cutomer to the existing list of customers
        UnProcessedCustomers.Add(customer);
        AllCSVCustomers.Add(customer); 
        HandleCSV();
        ReadCSV(FindDate());
        HasAnEnquiryBeenAdded = true;
    }

我尝试用

替换逗号
"\,"   "\\," 

并将整个部分用引号括起来,但网格仍然将这些单词分开?

<DataGrid x:Name="dgCustomers" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding UnProcessedCustomers, Mode=TwoWay}" Grid.Column="0" Margin="326,470,26,29" Grid.ColumnSpan="2">
        <DataGrid.Columns>
            <DataGridComboBoxColumn Header="Converted?" 
                    SelectedItemBinding="{Binding Converted, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    >
                <DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="ItemsSource" Value="{Binding DataContext.Converted, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
                    </Style>
                </DataGridComboBoxColumn.ElementStyle>
                <DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="ItemsSource" Value="{Binding DataContext.Converted, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
                    </Style>
                </DataGridComboBoxColumn.EditingElementStyle>
            </DataGridComboBoxColumn>
        </DataGrid.Columns>
    </DataGrid>

Example of problem

0 个答案:

没有答案