My DataGrid is displaying all my data as CheckBoxes, even when the values aren't booleans.
This is my XAML:
Code:
<sdk:DataGrid AutoGenerateColumns="False" Height="520" HorizontalAlignment="Left" Margin="0,89,0,0" Name="tblUsers" VerticalAlignment="Top" Width="1060" AlternatingRowBackground="#414A4A4E" AreRowDetailsFrozen="False" ItemsSource="{Binding}" DataContext="{Binding}" SelectionChanged="tblUsers_SelectionChanged">
<sdk:DataGrid.Columns>
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Username" Width="Auto" Binding="{Binding Path=Username}" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Password" Width="Auto" Binding="{Binding Password}" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Email" Width="Auto" Binding="{Binding Email}" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Verification" Width="Auto" Binding="{Binding Verification}" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Pool" Width="Auto" Binding="{Binding Pool}"/>
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Allow_Messaging" Width="Auto" Binding="{Binding Allow_Messaging}"/>
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Rating" Width="Auto" Binding="{Binding Rating}"/>
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Rating_Number" Width="Auto" Binding="{Binding Rating_Number}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
This is the Class it is bound to:
Code:
public class UserTableSource
{
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Verification { get; set; }
public string Pool { get; set; }
public bool Allow_Messaging { get; set; }
public double Rating { get; set; }
public int Rating_Number { get; set; }
public UserTableSource()
{
}
public UserTableSource(UserTableSource rhs)
{
Username = rhs.Username;
Password = rhs.Password;
Email = rhs.Email;
Verification = rhs.Verification;
Pool = rhs.Pool;
Allow_Messaging = rhs.Allow_Messaging;
Rating = rhs.Rating;
Rating_Number = rhs.Rating_Number;
}
}
This code just gets the MySQL Results (in the form of a string, joined by CHAR_188), and adds them to the datagrid.
Code:
result = result.TrimEnd(CHAR_188);
string[] users = result.Split(CHAR_188);
object[] fields;
userData.Clear();
originalUserData.Clear();
for (int n = 0; n < users.Length; n++)
{
fields = users[n].Split(DOUBLE_BAR);
UserTableSource newData = new UserTableSource();
newData.Username= fields[0].ToString();
newData.Password = fields[1].ToString();
newData.Email = fields[2].ToString();
newData.Verification = fields[3].ToString();
newData.Pool = fields[4].ToString();
newData.Allow_Messaging = Convert.ToBoolean(fields[5]).ToString();
newData.Rating = Convert.ToDouble(fields[6]);
newData.Rating_Number = Convert.ToInt32(fields[7]);
userData.Add(newData);
}
foreach (UserTableSource data in userData)
originalUserData.Add(new UserTableSource(data));
tblUsers.DataContext = null;
tblUsers.DataContext = userData;
}