0

我正在尝试将数据表的数据绑定到文本框。它工作正常,但它只显示数据表的最后一行。是否可以显示数据表的所有行?

XAML:

<Window x:Class="messenger.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
    <TextBox Height="203" HorizontalAlignment="Left" Name="conversationInput" VerticalAlignment="Top" Width="491" Margin="12,3,0,0" IsReadOnly="True">
        <TextBox.Text>
            <MultiBinding StringFormat="{0} : {1}">
                <Binding Path="date" />
                <Binding Path="message" />
            </MultiBinding>
        </TextBox.Text>
    </TextBox>
</Grid>

后面的代码:

    public DataTable loadConversation()
    {
        DataTable conversation = new DataTable();
        string loadMessages = "select message, date from Messages where userID=1";
        ad = new MySqlDataAdapter(loadMessages, connection);
        ad.Fill(conversation);
        return conversation;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        conversationInput.DataContext = loadConversation().DefaultView;
    }

提前致谢, Fluxxi

4

2 回答 2

0

TextBox是如何设计的。您应该改用ListBox(或类似的)控件。

于 2013-02-23T14:07:07.153 回答
0

是的,但您将需要使用某种中继器控件 - 例如DataGridListView

于 2013-02-23T14:07:18.707 回答