ListView DataView, it shows me this letters "System.Data.Row.View"


Joined
Jan 2, 2014
Messages
13
Reaction score
0
Hi there,

this code works fine, but it shows me "System.Data.Row.View" instead of those real Content.

But, I gave that View a DataTable like that, then I got the real content:
I dont see any diffrent between a datable like this or a datatable wich will fill with an SQLAdapter?
Code:
public DataTable myDataTable { get; set; }

myDataTable = new DataTable();
        myDataTable.Columns.Add("Start");
        myDataTable.Columns.Add("End");

        DataRow dr = myDataTable.NewRow();
        dr[0] = "Jo";
        dr[1] = "Doug";
        myDataTable.Rows.Add(dr);

        DataRow dr1 = myDataTable.NewRow();
        dr1[0] = "Jam";
        dr1[1] = "Pearl";
        myDataTable.Rows.Add(dr1);
XAML Code
Code:
<Window x:Class="Wpf_Binding_Listview.MainWindow"
        xmlns="...schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="...schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:Wpf_Binding_Listview"
         Height="400" Width="500" Title="Binding Listview">
   
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="138*" />
            <ColumnDefinition Width="209*" />
            <ColumnDefinition Width="156*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="76*" />
            <RowDefinition Height="235*" />
        </Grid.RowDefinitions>
       
        <ListView Name="LvView1" Grid.Column="1" Grid.Row="1"/> 
    </Grid>
</Window>
Code-Behind
Code:
public class Viewing
{
    
    public BindingListCollectionView myView { get; set; }    

    public Viewing()
    {

        SqlConnection con = new SqlConnection();
        SqlCommand myCmd = new SqlCommand();
        DataSet ds = new DataSet();


        con.ConnectionString = "Data Source=(local);" +
                   "Initial Catalog=Northwind;" +
                   "Integrated Security=sspi";

        con.Open();
        myCmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter();
       

        myCmd.CommandText = "SELECT * FROM Shippers";
        da.SelectCommand = myCmd;
        da.Fill(ds, "tblShippers");

        DataTable dt;
        dt = ds.Tables["tblShippers"];   

        myView = new BindingListCollectionView(new DataView(dt) { RowFilter = "CompanyName like 'S%'" });      

    }
 
Ad

Advertisements

Joined
Jan 2, 2014
Messages
13
Reaction score
0
well, I got the answer, those xaml code needs an update:

Code:
<ListView.View>
                <GridView>
                    <GridViewColumn Header="ID" Width="80" DisplayMemberBinding="{Binding ShipperID}"/>
                    <GridViewColumn Header="Customer" Width="100" DisplayMemberBinding="{Binding Contactname}"/>                  
                </GridView>
            </ListView.View>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top