1

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.

3
  • 2
    The fact that every code example is in C# should be telling you something about VB.NET's usefulness... Commented Apr 4, 2010 at 20:06
  • 1. You could use one of the C#-to-VB converters to convert the example code (ask Google about these converters). 2. I don't understand what you are trying to do: You talk about "adding item rows ", but your code seems to add columns ... Commented Apr 4, 2010 at 20:09
  • 3
    Matti, VB.NET and C# are functionally equivalent in most areas including I think everything that WPF is concerned with. If he or his team are more comfortable with VB than with C#, then VB is going to be a lot more "useful" to them than C#; and it can easily do what he needs it to. Knocking VB's "usefulness" is poor advice. Commented Apr 4, 2010 at 20:53

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

0

Disclaimer: C#

this is the starting point:
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1

C# to VB.Net:
http://www.developerfusion.com/tools/convert/csharp-to-vb/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.