This question is locked. New answers and comments are not allowed.
Hi
I am struggling with displaying my data correctly in the . I have an SQLite database and a two column data grid. I am able to get one column from the database and display it in both columns of the data grid. I am also able to grab both columns of the database and display them combined in the two data grid columns.
I need to display each database column in their respective data grid column. I believe it is a binding issue. I have the names as "Output" and have its item source as the list of data from the database currently.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using DataAccessLibrary;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace QuoteTool
{
/// <
summary
>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </
summary
>
public sealed partial class CustomerContacts : Page
{
public CustomerContacts()
{
this.InitializeComponent();
Output.ItemsSource = DataAccess.GetData();
}
}
}
01.
using System;
02.
using System.Collections.Generic;
03.
using System.Linq;
04.
using System.Text;
05.
using System.Threading.Tasks;
06.
using Microsoft.Data.Sqlite;
07.
08.
namespace DataAccessLibrary
09.
{
10.
11.
public class DataAccess
12.
{
13.
//public static object DataGrid { get; }
14.
15.
public static void InitializeDatabase()
16.
{
17.
using (SqliteConnection db =
18.
new SqliteConnection("Filename=sqliteSample.db"))
19.
{
20.
db.Open();
21.
22.
String tableCommand = "CREATE TABLE IF NOT " +
23.
"EXISTS MyTable (Primary_Key STRING PRIMARY KEY , " +
24.
"Text_Entry STRING)";
25.
26.
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
27.
28.
createTable.ExecuteReader();
29.
}
30.
31.
32.
}
33.
34.
35.
36.
public static List<
String
> GetData()
37.
{
38.
List<
String
> entries = new List<
string
>();
39.
40.
41.
using (SqliteConnection db =
42.
new SqliteConnection("Filename=sqliteSample.db"))
43.
{
44.
db.Open();
45.
46.
SqliteCommand selectCommand = new SqliteCommand
47.
("SELECT * from MyTable", db);
48.
49.
SqliteDataReader query = selectCommand.ExecuteReader();
50.
51.
while (query.Read())
52.
{
53.
entries.Add(query.GetString(0));
54.
55.
}
56.
while (query.Read())
57.
{
58.
entries.Add(query.GetString(1));
59.
60.
}
61.
62.
63.
db.Close();
64.
}
65.
66.
67.
return entries;
68.
}
69.
70.
71.
72.
}
73.
}
01.
<
Page
02.
04.
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
05.
xmlns:local
=
"using:QuoteTool.QuoteTool.CustomerContacts"
06.
xmlns:local1
=
"using:QuoteTool"
07.
xmlns:d
=
"http://schemas.microsoft.com/expression/blend/2008"
08.
xmlns:mc
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
09.
xmlns:Custom
=
"using:Telerik.UI.Xaml.Controls.Grid"
10.
xmlns:telerikGrid
=
"using:Telerik.UI.Xaml.Controls.Grid"
11.
xmlns:core
=
"using:Telerik.Data.Core"
12.
13.
x:Class
=
"QuoteTool.CustomerContacts"
14.
mc:Ignorable
=
"d"
FontFamily
=
"Bell MT"
>
15.
<
Page.Background
>
16.
<
ImageBrush
x:Name
=
"background"
ImageSource
=
"Quote Tool background MainPage.png"
17.
Stretch
=
"None"
AlignmentX
=
"Center"
AlignmentY
=
"Center"
/>
18.
</
Page.Background
>
19.
20.
<
Grid
x:Name
=
"Grid"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Center"
21.
Margin
=
"0,115,0,0"
Height
=
"635"
Width
=
"823"
>
22.
<
TextBox
Name
=
"Input_Box"
HorizontalAlignment
=
"Left"
Margin
=
"132,10,0,0"
23.
VerticalAlignment
=
"Top"
Width
=
"664"
></
TextBox
>
24.
<
Button
Click
=
"AddData"
HorizontalAlignment
=
"Left"
Margin
=
"309,73,0,0"
25.
VerticalAlignment
=
"Top"
Width
=
"107"
Height
=
"34"
Content
=
"ADD"
></
Button
>
26.
<
telerikGrid:RadDataGrid
Name
=
"Output"
HorizontalAlignment
=
"Left"
27.
Margin
=
"0,124,0,0"
VerticalAlignment
=
"Top"
Height
=
"526"
Width
=
"938"
28.
AutoGenerateColumns
=
"False"
UserEditMode
=
"Inline"
29.
FocusVisualSecondaryBrush
=
"#F70C0000"
Foreground
=
"#FF0C0000"
30.
FontFamily
=
"Segoe UI"
RowHeight
=
"200"
>
31.
<
telerikGrid:RadDataGrid.Columns
>
32.
<
telerikGrid:DataGridTemplateColumn
x:Name
=
"column1"
33.
Header
=
"Primary Key"
IsVisible
=
"True"
>
34.
<
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
35.
<
DataTemplate
>
36.
<
TextBox
Text
=
"{Binding}"
/>
37.
</
DataTemplate
>
38.
</
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
39.
</
telerikGrid:DataGridTemplateColumn
>
40.
<
telerikGrid:DataGridTemplateColumn
Header
=
"Text Entry"
41.
IsVisible
=
"True"
>
42.
<
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
43.
<
DataTemplate
>
44.
<
TextBlock
Text
=
"{Binding}"
45.
FontFamily
=
"Segoe UI"
/>
46.
</
DataTemplate
>
47.
</
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
48.
</
telerikGrid:DataGridTemplateColumn
>
49.
</
telerikGrid:RadDataGrid.Columns
>
50.
</
telerikGrid:RadDataGrid
>
51.
</
Grid
>
52.
</
Grid
>
53.
</
Page
>