views:

262

answers:

3

Im getting crazy with it. It is so easy in windows form, but in wpf it seems to be different. Every example i find is in C# and i cant addapt it. Well, this is the code i have. Atm, i have just defined the columns:

 'diseño de las columnas
        Dim item As ListViewItem = New ListViewItem
        Dim Mi_Lista As GridView = New GridView
        Mi_Lista.AllowsColumnReorder = True

        Dim cine As New GridViewColumn()
        Dim Si3d As New GridViewColumn
        cine.Header = "Cine"
        cine.DisplayMemberBinding = New Binding("Cine")
        Si3d.DisplayMemberBinding = New Binding("si3D")
        cine.Width = 140
        Si3d.Header = "3D"
        Si3d.Width = 50
        Mi_Lista.Columns.Add(cine)
        Mi_Lista.Columns.Add(Si3d)

Thanks in advance.

+1  A: 

There are two ways to do this:

  1. Add ListViewItems to the ListView.Items property. This is the WinForms way but is not idiomatic in WPF.
  2. Set the ListView.ItemsSource property. WPF will then create a row for each entry in the ItemsSource collection. You will not need to Dim ListViewItem objects yourself in this case. This is idiomatic WPF.

To do option 2, write something like this:

Dim data As ObservableCollection(Of Something) = New ObservableCollection(Of Something)
' Populate the collection
lv.ItemsSource = data

Note that here lv is your ListView, not your GridView. Also you would normally define your ListView and columns in XAML rather than code, e.g.

<ListView Name="lv">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="Cine"
                      DisplayMemberBinding="{Binding Cine}"
                      Width="140" />
    </GridView>
  </ListView.View>
</ListView>
itowlson
A: 

Yeah, i got it some days ago, thanks. For future users:

Public Sub LlenarLista(ByVal película As String)
    ' MessageBox.Show(película)
    Dim dtLista As DataTable
    Dim dt As DataTable = New DataTable()
    Dim connetionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=Cinépolis.mdb"
    Dim connection As OleDbConnection = New OleDbConnection(connetionString)
    connection.Open()
    Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT Cines.Nombre as nombre, Películas.Título, Proyecciones.[3D] AS p3d, Cines.web, Cines.Ubicacion as Ubicación, Cines.Parking FROM Películas INNER JOIN (Cines INNER JOIN Proyecciones ON Cines.IdCine = Proyecciones.IDCine) ON Películas.IDPelícula = Proyecciones.IDPelícula WHERE (((Películas.Título)='" & película & "')); ", connection)
    da.Fill(dt)
    dtLista = dt
    lvCines.DataContext = dtLista
    lvCines.SetBinding(ListView.ItemsSourceProperty, New Binding)

    connection.Close()

Y el diseño:

            <GridView ColumnHeaderTemplate="{StaticResource estiloCabecera}" >
                <GridViewColumn    Header="Cine" DisplayMemberBinding="{Binding nombre}"   />

                <GridViewColumn Header="3D" Width="50" DisplayMemberBinding="{Binding p3d}"/>
                <GridViewColumn Header="Web" Width="150" DisplayMemberBinding="{Binding web}"/>
            </GridView>
        </ListView.View>

    </ListView>
leviatan1001