Click here to Skip to main content
14,423,178 members

Silverlight / WPF

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 4:09
cofounderChris Maunder16-Jul-09 4:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 4:05
cofounderChris Maunder16-Jul-09 4:05 
QuestionIm new bie help me fix 1 erorr on wpf, i cant do it? Pin
Member 1468037212-Jan-20 17:07
MemberMember 1468037212-Jan-20 17:07 
GeneralRe: Im new bie help me fix 1 erorr on wpf, i cant do it? Pin
Richard MacCutchan12-Jan-20 23:12
communityengineerRichard MacCutchan12-Jan-20 23:12 
AnswerRe: Im new bie help me fix 1 erorr on wpf, i cant do it? Pin
ZurdoDev13-Jan-20 2:07
mveZurdoDev13-Jan-20 2:07 
QuestionRoutedEvent Pass EventArg Pin
Kevin Marois11-Jan-20 17:42
professionalKevin Marois11-Jan-20 17:42 
AnswerRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz11-Jan-20 21:24
mveGerry Schmitz11-Jan-20 21:24 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois12-Jan-20 11:05
professionalKevin Marois12-Jan-20 11:05 
GeneralRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz13-Jan-20 14:23
mveGerry Schmitz13-Jan-20 14:23 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 6:18
professionalKevin Marois14-Jan-20 6:18 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 6:43
professionalKevin Marois14-Jan-20 6:43 
AnswerRe: RoutedEvent Pass EventArg Pin
Richard Deeming13-Jan-20 9:00
communityengineerRichard Deeming13-Jan-20 9:00 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 10:02
professionalKevin Marois14-Jan-20 10:02 
QuestionCalculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 20:44
MemberMember 146803727-Jan-20 20: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 22:17
communityengineerRichard MacCutchan7-Jan-20 22:17 
AnswerRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 22:49
MemberMember 146803727-Jan-20 22:49 
SuggestionRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Richard Deeming8-Jan-20 1:46
communityengineerRichard Deeming8-Jan-20 1:46 
QuestionRefresh Attached Property? Pin
Kevin Marois7-Jan-20 11:17
professionalKevin Marois7-Jan-20 11:17 
AnswerRe: Refresh Attached Property? Pin
Richard Deeming8-Jan-20 2:18
communityengineerRichard Deeming8-Jan-20 2:18 
QuestionWPF Exception - Send Error Report Pin
Kevin Marois30-Dec-19 8:41
professionalKevin Marois30-Dec-19 8:41 
AnswerRe: WPF Exception - Send Error Report Pin
Richard MacCutchan30-Dec-19 11:13
communityengineerRichard MacCutchan30-Dec-19 11:13 
AnswerRe: WPF Exception - Send Error Report Pin
jimmson2-Jan-20 4:15
Memberjimmson2-Jan-20 4:15 
AnswerRe: WPF Exception - Send Error Report Pin
Gerry Schmitz2-Jan-20 21:09
mveGerry Schmitz2-Jan-20 21:09 
AnswerRe: WPF Exception - Send Error Report Pin
Mycroft Holmes3-Jan-20 11:49
MemberMycroft Holmes3-Jan-20 11:49 
QuestionMenuButton CanExecute Firing Wrong Pin
Kevin Marois24-Dec-19 12:42
professionalKevin Marois24-Dec-19 12:42 

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.