Hey folks,
I´ve tried, for 2 days now, to bind stringelements of an array that had read out its data from a textfile to a combobox, that is embedded in a datagrid. The problem is that the data won´t show up. I tried many different things.
My application builds up on this tutorial: using-the-wpf-toolkit-datagrid
There the Combobox' ItemsSource is directly connected to a new table. I tried to declare a table first and insert the content of the combo with a loop, but connecting the table to the ItemsSource doesn´t work.
Now I try the databinding solution from this: wpf-tutorial-using-the-listview-part-3-in-place-edit
I´ve just took the combobox part, so that it is bound to a ObservableCollection .
My code looks like this and doesn´t work as well:
Gruppenspiele.xaml
x:Name="Grpspiellist" VerticalAlignment="Top"
Width="430"
ItemsSource="{Binding ElementName=This,
Path=Spieldaten}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Spielrow}"
Header="Spiel"/>
<DataGridComboBoxColumn Header="Erste Mannschaft"
ItemsSource="{Binding
ElementName=This,
Path=ManschComb}"
SelectedItemBinding=
{Binding ErstRow}"/>
<DataGridComboBoxColumn Header="Zweite Mannschaft"
ItemsSource="{Binding
ElementName=This,
Path=ManschComb}"
SelectedItemBinding=
"{Binding ZweitRow}"/>
<DataGridTemplateColumn Header="Spieldatum">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding
Date, Mode=TwoWay}"
SelectedDateFormat="Short"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding
Date,StringFormat=d}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Gruppenspiele.xamls.cs:
namespace Fußballtipp
{
public partial class Gruppenspiele : Window
{
private DataTable _Spieldaten;
private ObservableCollection<string> _ManschComb =
new ObservableCollection<string>();
public Gruppenspiele()
{
StreamReader MannschIn =
new StreamReader("Daten\\Mannschaften.txt");
string VorhMannschraw = MannschIn.ReadToEnd();
string[] VorhMannsch = Regex.Split(VorhMannschraw, "\r\n");
for (int i = 0; i < VorhMannsch.Count() - 1; i++)
{
_ManschComb.Add(VorhMannsch[i]);
}
MannschIn.Close();
_Spieldaten = new DataTable();
_Spieldaten.Columns.Add(new DataColumn("Spielrow",
typeof(int)));
_Spieldaten.Columns.Add(new DataColumn("ErstRow",
typeof(string)));
_Spieldaten.Columns.Add(new DataColumn("ZweitRow",
typeof(string)));
_Spieldaten.Columns.Add(new DataColumn("Date", typeof(string)));
InitializeComponent();
}
//some button event handlers...
public DataTable Spieldaten
{ get { return _Spieldaten; } }
public ObservableCollection<string> ManschComb
{ get { return _ManschComb; } }
//----------------------------------------------------------
//Button to add new row:
private void neuzeil_Click(object sender, RoutedEventArgs e)
{
var row = _Spieldaten.NewRow();
row["Spielrow"] = Grpspiellist.Items.Count;
row["ErstRow"] = "<Mannschaft wählen>";
row["ZweitRow"] = "<Mannschaft wählen>";
row["Date"] = "Datum wählen";
_Spieldaten.Rows.Add(row);
}
//----------------------------------------------------------
Add Comment
[language] [/language]
Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]
See here for supported languages.
Javascript must be enabled to submit anonymous comments - or you can login.