Click here to Skip to main content
15,028,757 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz11-Jan-20 20:24
mveGerry Schmitz11-Jan-20 20:24 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois12-Jan-20 10:05
professionalKevin Marois12-Jan-20 10:05 
GeneralRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz13-Jan-20 13:23
mveGerry Schmitz13-Jan-20 13:23 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 5:18
professionalKevin Marois14-Jan-20 5:18 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 5:43
professionalKevin Marois14-Jan-20 5:43 
AnswerRe: RoutedEvent Pass EventArg Pin
Richard Deeming13-Jan-20 8:00
mveRichard Deeming13-Jan-20 8:00 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 9:02
professionalKevin Marois14-Jan-20 9:02 
QuestionCalculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 19:44
MemberMember 146803727-Jan-20 19:44 
I have a small program, because I'm new, my program is to bring data from sql sever to textbox via combobox option and use the value shown in that textbox to calculate the + I have made it to the step of putting up the data, now thanks to you to help me with the value calculation in the textbox, thank you for your help. 

xaml code :

 <Window.Resources>
        <local:SimpleMath x:Key="MyFriends"/>
    </Window.Resources>

    <Grid>
        <Label Content="code" HorizontalAlignment="Left" Margin="38,52,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="pieces" HorizontalAlignment="Left" Margin="38,126,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="layers" HorizontalAlignment="Left" Margin="38,196,0,0" 
               VerticalAlignment="Top" Width="46" Height="30"/>
        <Label Content="production pieces" HorizontalAlignment="Left" 
               Margin="0,278,0,0" VerticalAlignment="Top" Width="108" Height="25"/>
        <TextBox x:Name="txtcode" 
                 Text="{Binding Txtcode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" Margin="124,52,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtpieces" 
                 Text="{Binding Txtpieces, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtlayers" 
                 Text="{Binding Txtlayers,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtproductionpieces" 
                 Text="{Binding Txtproductionpieces,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" Margin="124,280,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <ComboBox x:Name="comboBox1" ItemsSource="{Binding Source={StaticResource MyFriends}}" 
                  HorizontalAlignment="Left" Margin="418,52,0,0" VerticalAlignment="Top" 
                  Width="319" Height="36" SelectionChanged="ComboBox1_SelectionChanged"/>
        <TextBox x:Name="txtseccond" 
                 Text="{Binding Txtseccond,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,345,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <Label Content="seccond" HorizontalAlignment="Left" Margin="38,345,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <TextBlock Text="{Binding A, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" 
                   HorizontalAlignment="Left" Margin="418,133,0,0" TextWrapping="Wrap"  
                   VerticalAlignment="Top" Height="23" Width="248"/>
        <TextBox Text="{Binding No1,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="21" Margin="426,210,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="303"/>
    </Grid>
</Window>


C# code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace comboboxapp1
{
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public SimpleMath Formular { get; set; }
public object SelectedValue { get; private set; }

public MainWindow()
{
Formular = new SimpleMath()
{
Txtcode = 0,
Txtpieces = 0,
Txtlayers = 0,
Txtproductionpieces = 0,
Txtseccond = 0,

};
InitializeComponent();
DataContext = Formular;
Fillcombobox();
}
private void MainWindow_Load(object sender, EventArgs e)
{

}
public void Fillcombobox()
{
SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial
Catalog=LUAT;Integrated Security=True");

string sql = " select * from comboboxnew ";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader myreader;
try
{
con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string sname = myreader.GetInt32(0).ToString();
comboBox1.Items.Add(sname);

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}
}
public class SimpleMath : INotifyPropertyChanged
{
private int no1;

public int No1
{
get { return no1; }
set
{
no1 = value;
OnPropertyChanged("No1");
OnPropertyChanged("A");
}
}
private int txtcode;

public int Txtcode
{
get { return txtcode; }
set
{
txtcode = value;
OnPropertyChanged("Txtcode");
OnPropertyChanged("A");
}
}
private int txtpieces;

public int Txtpieces
{
get { return txtpieces; }
set
{
txtpieces = value;
OnPropertyChanged("Txtcode");
OnPropertyChanged("A");
}
}
private int txtlayers;

public int Txtlayers
{
get { return txtlayers; }
set
{
txtlayers = value;
OnPropertyChanged("Txtlayers");
OnPropertyChanged("A");
}
}
private int txtproductionpieces;

public int Txtproductionpieces
{
get { return txtproductionpieces; }
set
{
txtproductionpieces = value;
OnPropertyChanged("Txtproductionpieces");
OnPropertyChanged("A");
}
}
private int txtseccond;

public int Txtseccond
{
get { return txtseccond; }
set
{
txtseccond = value;
OnPropertyChanged("Txtseccond");
OnPropertyChanged("A");
}
}
public double A => No1;

public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial
Catalog=LUAT;Integrated Security=True");
// string sql = " select * from comboboxnew where code = '" + comboBox1.Text+ "';";
string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem +
"';";
//Console.WriteLine(comboBox1.Text);
//MessageBox.Show(comboBox1.Text);
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader myreader;
try
{
con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string code = myreader.GetInt32(0).ToString();
string pieces = myreader.GetInt32(1).ToString();
string layers = myreader.GetInt32(2).ToString();
string productionpieces = myreader.GetInt32(3).ToString();
string seccond = myreader.GetInt32(4).ToString();
txtcode.Text = code;
//txtcode.Text =SelectedValue;
txtpieces.Text = pieces;
//txtpieces.Text = "New value";
txtlayers.Text = layers;
//txtlayers.Text = "New value";
txtproductionpieces.Text = productionpieces;
//txtproductionpieces.Text = "New value";
txtseccond.Text = seccond;
//txtseccond.Text = "New value";

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
QuestionRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Richard MacCutchan7-Jan-20 21:17
mveRichard MacCutchan7-Jan-20 21:17 
AnswerRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 21:49
MemberMember 146803727-Jan-20 21:49 
SuggestionRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Richard Deeming8-Jan-20 0:46
mveRichard Deeming8-Jan-20 0:46 
QuestionRefresh Attached Property? Pin
Kevin Marois7-Jan-20 10:17
professionalKevin Marois7-Jan-20 10:17 
AnswerRe: Refresh Attached Property? Pin
Richard Deeming8-Jan-20 1:18
mveRichard Deeming8-Jan-20 1:18 
QuestionWPF Exception - Send Error Report Pin
Kevin Marois30-Dec-19 7:41
professionalKevin Marois30-Dec-19 7:41 
AnswerRe: WPF Exception - Send Error Report Pin
Richard MacCutchan30-Dec-19 10:13
mveRichard MacCutchan30-Dec-19 10:13 
AnswerRe: WPF Exception - Send Error Report Pin
jimmson2-Jan-20 3:15
Memberjimmson2-Jan-20 3:15 
AnswerRe: WPF Exception - Send Error Report Pin
Gerry Schmitz2-Jan-20 20:09
mveGerry Schmitz2-Jan-20 20:09 
AnswerRe: WPF Exception - Send Error Report Pin
Mycroft Holmes3-Jan-20 10:49
professionalMycroft Holmes3-Jan-20 10:49 
QuestionMenuButton CanExecute Firing Wrong Pin
Kevin Marois24-Dec-19 11:42
professionalKevin Marois24-Dec-19 11:42 
AnswerRe: MenuButton CanExecute Firing Wrong Pin
Gerry Schmitz26-Dec-19 6:34
mveGerry Schmitz26-Dec-19 6:34 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Kevin Marois26-Dec-19 7:38
professionalKevin Marois26-Dec-19 7:38 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Gerry Schmitz27-Dec-19 5:58
mveGerry Schmitz27-Dec-19 5:58 
AnswerRe: MenuButton CanExecute Firing Wrong Pin
Mycroft Holmes27-Dec-19 14:21
professionalMycroft Holmes27-Dec-19 14:21 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Kevin Marois27-Dec-19 14:34
professionalKevin Marois27-Dec-19 14:34 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Mycroft Holmes27-Dec-19 14:48
professionalMycroft Holmes27-Dec-19 14:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.