Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<Grid>
      <Rectangle>
          <Rectangle.Fill>
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                  <GradientStop Color="#01a0fe" Offset="0"/>
                  <GradientStop Color="#2ec091" Offset="1"/>
              </LinearGradientBrush>
          </Rectangle.Fill>
          <Rectangle.OpacityMask>
              <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                  <GradientStop Color="#01a0fe" Offset="0"/>
                  <GradientStop Color="#2ec091" Offset="0.5"/>
              </LinearGradientBrush>
          </Rectangle.OpacityMask>
      </Rectangle>
      <Grid Height="650" Width="1080">
          <Grid Height="650" Width="245" HorizontalAlignment="Left">
              <StackPanel HorizontalAlignment="Left" Width="228" Margin="0,100,0,0">
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel>
                          <StackPanel Orientation="Horizontal">
                              <Image Source="image.png/dashboard.png" Margin="20,0,0,0" Width="56" Height="45"/>
                              <Button Name="btnDasboard" Content="Dashboard"  VerticalAlignment="Top" FontWeight="Bold" FontSize="18" Padding="15,12,0,0" Width="145" HorizontalAlignment="Center" Foreground="White" Height="45" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" Background="{x:Null}" Click="BtnDasboard_Click"/>
                          </StackPanel>
                      </StackPanel>
                  </Grid>
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel Orientation="Horizontal">
                          <Image Source="image.png/master.png" Margin="20,0,0,0" Width="56" Height="45"/>
                          <Button Name="btnMaster" Content="Master" FontWeight="Bold" FontSize="18" Padding="15,12,0,0" Width="145" HorizontalAlignment="Center" Foreground="White" Height="Auto" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" Background="{x:Null}" Click="BtnMaster_Click"/>
                      </StackPanel>
                  </Grid>
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel Orientation="Horizontal">
                          <Image Source="image.png/inventory.png" Margin="20,0,0,0" Width="54" Height="36"/>
                          <Button x:Name="Inventory" Content="Inventory" VerticalAlignment="Top"  FontWeight="Bold" FontSize="18" Padding="15,12,0,0"  Width="145" HorizontalAlignment="Center" Foreground="White" VerticalContentAlignment="Top" Height="45" Background="{x:Null}"/>
                      </StackPanel>
                  </Grid>
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel Orientation="Horizontal">
                          <Image Source="image.png/get-money.png" Margin="20,0,0,0" Width="55"/>
                          <Button x:Name="Payroll" Content="Payroll" VerticalAlignment="Top" FontWeight="Bold" FontSize="18" Padding="15,12,0,0" Width="145" HorizontalAlignment="Center" Foreground="White" VerticalContentAlignment="Top" Height="45" Background="{x:Null}"/>
                      </StackPanel>
                  </Grid>
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel Orientation="Horizontal">
                          <Image Source="image.png/report.png" Margin="20,0,0,0" Width="54" Height="36"/>
                          <Button x:Name="Reports" Content="Reports" VerticalAlignment="Center"  FontWeight="Bold" FontSize="18" Padding="15,12,0,0"  Width="145" HorizontalAlignment="Left" Foreground="White" VerticalContentAlignment="Top" Height="46" Background="{x:Null}"/>
                      </StackPanel>
                  </Grid>
                  <Grid Height="45" Margin="0 20 0 0">
                      <StackPanel Orientation="Horizontal">
                          <Image Source="image.png/settings.png" Margin="20,0,0,0" Width="54" Height="36"/>
                          <Button x:Name="Settings" Content="Settings" VerticalAlignment="Center" FontWeight="Bold" FontSize="18" Padding="15,12,0,0" Width="145" HorizontalAlignment="Left" Foreground="White" Height="45" VerticalContentAlignment="Top" Background="{x:Null}"/>
                      </StackPanel>
                  </Grid>
              </StackPanel>
          </Grid>
          <Grid Margin="245,0,0,0">
              <Button Name="Add_New" Content="Add New" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="107"   Margin="712,0,0,608" FontWeight="Bold" Foreground="#DD000000" Background="White" Click="Add_New_Click"/>
              <DataGrid Name="dataGrid" AutoGenerateColumns="False" CanUserAddRows="False"
                  Margin="0,65,10,20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  RowBackground="White" FontWeight="Bold" Foreground="Black"
                  ScrollViewer.CanContentScroll="True"
                  AlternatingRowBackground="#f2f2f2" BorderBrush="#000" BorderThickness="1"
                  ScrollViewer.HorizontalScrollBarVisibility="Visible"
                  ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="dataGrid_SelectionChanged" Background="White">
                  <DataGrid.Columns>
                      <DataGridTextColumn Header="Company id" Binding="{Binding Path='company_id'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Company Name" Binding="{Binding Path='company_name'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Caption" Binding="{Binding Path='caption'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Address1" Binding="{Binding Path='address1'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Address2" Binding="{Binding Path='address2'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="MobileNo" Binding="{Binding Path='mobileno'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Emailid" Binding="{Binding Path='email'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Gst" Binding="{Binding Path='gst'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Cloud Api" Binding="{Binding Path='cloudApi'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Username" Binding="{Binding Path='username'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Password" Binding="{Binding Path='password'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Selectusertype" Binding="{Binding Path='selectusertype'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Uploadlogo" Binding="{Binding Path='uploadlogo'}" IsReadOnly="True" />
                      <DataGridTextColumn Header="Activation Key" Binding="{Binding Path='activationkey'}" IsReadOnly="True" />
                      <DataGridTemplateColumn Header="Edit">
                          <DataGridTemplateColumn.CellTemplate>
                              <DataTemplate>
                                  <Button Name="btnEdit" Content="Edit" Click="btnEdit_Click"/>
                              </DataTemplate>
                          </DataGridTemplateColumn.CellTemplate>
                      </DataGridTemplateColumn>
                      <DataGridTemplateColumn Header="Delete">
                          <DataGridTemplateColumn.CellTemplate>
                              <DataTemplate>
                                  <Button Name="btnDel" Content="Delete" Click="btnDel_Click" />
                              </DataTemplate>
                          </DataGridTemplateColumn.CellTemplate>
                      </DataGridTemplateColumn>
                  </DataGrid.Columns>
              </DataGrid>
          </Grid>
      </Grid>
  </Grid>


What I have tried:

public partial class New_Add_Profile : Window
    {
        string ConnectionString = @"Data Source=DESKTOP-89MGP64;Initial Catalog=new_restaurant_application;Integrated Security=True";
        public New_Add_Profile()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand("loadprofile_sp", conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cmd.Dispose();
            adapter.Dispose();
            conn.Close();
            dataGrid.ItemsSource = dt.DefaultView;
        }


        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void BtnDasboard_Click(object sender, RoutedEventArgs e)
        {
            Dashboard ds = new Dashboard();
            ds.Show();
            this.Hide();
        }

        private void BtnMaster_Click(object sender, RoutedEventArgs e)
        {
            Dashboard1 ds1 = new Dashboard1();
            ds1.Show();
            this.Hide();
        }

        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //try
            //{
            //    SqlConnection conn = new SqlConnection(ConnectionString);
            //    SqlCommand cmd = new SqlCommand("loadprofile_sp", conn);
            //    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            //    DataTable dt = new DataTable();
            //    adapter.Fill(dt);
            //    cmd.Dispose();
            //    adapter.Dispose();
            //    conn.Close();
            //    dataGrid.ItemsSource = dt.DefaultView;
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message.ToString());
            //}
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
                String ProductName = dataRowView[1].ToString();
                String ProductDescription = dataRowView[2].ToString();
                MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
                String ProductName = dataRowView[1].ToString();
                String ProductDescription = dataRowView[2].ToString();
                MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void Add_New_Click(object sender, RoutedEventArgs e)
        {
            Add_Profile ap = new Add_Profile();
            ap.Show();
            this.Hide();
        }
    }
Posted
Comments
[no name] 9-Sep-22 12:06pm    
None of the code you're showing is related to your question ... which amounts to: how to call a method in one window from another (in WPF). I suggest you rewrite your question accordingly (with only relevant code, if any).
prashanth manoj 10-Sep-22 1:37am    
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
try
{
Add_Profile ap = new Add_Profile();

ap.txtCompanyId.Text = SetValueForText1;
ap.txtCompanyName.Text = SetValueForText2;
ap.txtCaption.Text = this.dataGrid.CurrentItem.ToString();
ap.txtAddress1.Text = this.dataGrid.CurrentCell.ToString();
ap.txtAddress2.Text = this.dataGrid.CurrentColumn.ToString();
ap.txtMobile.Text = this.dataGrid.CurrentItem.ToString();
ap.txtEmail.Text = this.dataGrid.CanUserAddRows.ToString();
ap.txtGstin.Text = this.dataGrid.IsSynchronizedWithCurrentItem.Value.ToString();
ap.txtCloudApi.Text = this.dataGrid.ItemsSource.ToString();
ap.txtUsername.Text = this.dataGrid.CanUserResizeRows.ToString();
ap.txtPassword.Password = this.dataGrid.CanUserResizeRows.ToString();
ap.txtcombox.Text = this.dataGrid.CanUserResizeRows.ToString();
ap.txtActivationKey.Text = this.dataGrid.CanUserResizeRows.ToString();
ap.ShowDialog();
// ap.picUserimage.Source = this.dataGrid.CurrentColumn.ToString();
//DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
//String ProductName = dataRowView[1].ToString();
//String ProductDescription = dataRowView[2].ToString();
//MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

private void btnDel_Click(object sender, RoutedEventArgs e)
{
//if (txt.Text == "-" || lbluserid.Text == "")
//{
// MessageBox.Show("You are Not able to Delete Please select item", "Question", MessageBoxButton.OK, MessageBoxImage.Warning);
//}
try
{
if (MessageBox.Show("Do you want to Delete?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{

}
DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
String ProductName = dataRowView[1].ToString();
String ProductDescription = dataRowView[2].ToString();
MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
[no name] 10-Sep-22 11:28am    
We have a failure to communicate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900