Resolved WPF ListBox Binding Stumped

kwhelchel

Well-known member
Joined
Feb 28, 2020
Messages
53
Programming Experience
Beginner
Ok so yes working my way through WPF and a struggle lol. But so far I agree it is worth it @Skydiver thanks.
ok so I can bind my database with a Datagrid and get it to display but when I work with the list box i get all turned around for some reason. But the Datagrid is a bit more to my liking on the partial look of it.

MainWindow.xaml:
        <DataGrid  Margin="5,0,5,0" Name="ReportFilter"  Grid.Row="2" Grid.RowSpan="15"
                 Grid.Column="3" >
            <DataGrid.Columns>

                <DataGridTextColumn Binding="{Binding Name}" Width=" 10"/>

            </DataGrid.Columns>

        </DataGrid>
mainWindows.xaml.cs:
        public MainWindow()
        {
            InitializeComponent();
            bindListBox();

        }

        private void bindListBox()
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select closeid, e_date from [closeout]";
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable("Closeout");
            da.Fill(dt);


            ReportFilter.ItemsSource = dt.DefaultView;
reportviewer.PNG
 
Last edited:
Opps yup your right .
ok on the datagrid can I remove the headers and the grid lines ?
if so this will work perfect. If not what is needed to do this via a listbox?
 
Do it in Xaml
GridLinesVisibility="None"
HeadersVisibility="None"
You can also do it in your code behind file : Yourfile.xaml.cs
 
Back
Top Bottom