Hi,
I have a DataGrid in my MainWindow.xaml which has various columns. I have another windows 'AddFixtures.xaml' which has a load of text boxes in, I want the data from the text boxes in this window to go to rows in the datagrid in MainWindow.xaml.
What I have tried:
I have a class for Fixture in the code behind 'AddFixture.xaml:
public class Fixture
{
public int fixtureID { get; set; }
public int channelID { get; set; }
public string fixtureName { get; set; }
public string position { get; set; }
public string patch { get; set; }
public string mode { get; set; }
public string power { get; set; }
public string direction { get; set; }
}
which then I get all the data from the various text boxes when I click the 'Ok' button:
private void BtnAddFixture_Click(object sender, RoutedEventArgs e)
{
var data = new Fixture {
fixtureID = Int32.Parse(txtFixtureID.Text),
channelID = Int32.Parse(txtChannel.Text),
fixtureName = cbxFixture.Text,
position = cbxPosition.Text,
patch = cbxUniverse.Text + "." + txtChannel.Text,
mode = cbxMode.Text,
power = cbxSocca.Text + "." + cbxWay.Text,
direction = "Forwards"
};
}
So I literally just need to get the var 'data' to my 'MainWindow' to add the rows.
I have binded the class to my datagrid columns like this:
<DataGrid x:Name="FixtureView" AutoGenerateColumns="True" Grid.Column="1">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding fixtureID}" Header="Fixture ID" Width="*"/>
<DataGridTextColumn Binding="{Binding channelID}" Header="Channel ID" Width="*"/>
<DataGridTextColumn Binding="{Binding fixtureName}" Header="Name" Width="3.5*"/>
<DataGridTextColumn Binding="{Binding position}" Header="Position" Width="2*"/>
<DataGridTextColumn Binding="{Binding patch}" Header="Patch" Width="*"/>
<DataGridTextColumn Binding="{Binding mode}" Header="Mode" Width="1.5*"/>
<DataGridTextColumn Binding="{Binding power}" Header="Power" Width="*"/>
<DataGridTextColumn Binding="{Binding direction}" Header="Orientation" Width="2*"/>
</DataGrid.Columns>
</DataGrid>
Would be very greatfull if anyone could tell me what I need to do, have been searching for hours!