Click here to Skip to main content
15,887,676 members
Home / Discussions / WPF
   

WPF

 
QuestionSave DocumentViewer content as MS Word document Pin
sureshb_079-May-12 1:51
professionalsureshb_079-May-12 1:51 
QuestionResize and Edit Text in wpf Pin
NoufMohd8-May-12 1:17
NoufMohd8-May-12 1:17 
AnswerRe: Resize and Edit Text in wpf Pin
Mycroft Holmes8-May-12 12:29
professionalMycroft Holmes8-May-12 12:29 
Questiontry to add data on wpf DataGridColumn Pin
MemberDotNetting7-May-12 10:55
MemberDotNetting7-May-12 10:55 
AnswerRe: try to add data on wpf DataGridColumn Pin
Mycroft Holmes7-May-12 12:26
professionalMycroft Holmes7-May-12 12:26 
AnswerRe: try to add data on wpf DataGridColumn Pin
Wayne Gaylard7-May-12 20:09
professionalWayne Gaylard7-May-12 20:09 
GeneralRe: try to add data on wpf DataGridColumn Pin
MemberDotNetting7-May-12 23:23
MemberDotNetting7-May-12 23:23 
QuestionWPF DataGrid cell click Pin
LAPEC7-May-12 9:27
LAPEC7-May-12 9:27 
Hello Everyone

I did asked a question to my problem couple of days ago on: How can I display all the details of the employee in the textboxes, comboboxes, and checkbox when I click on the cell of the DataGrid?

Well somehow I managed to solve my problem with the help on searching on the internet, but I'm facing another problem.

When I run my application I'm displaying only the names of the employee from the database on the DataGrid, then when I click on DataGrid cell (of the employee name, to display all the details of that employee into textboxes, comboboxes, and checkbox) some-how it repeats the details of the employee into textboxes.

To be more clear to my problem:

In my database table (EmployeeDetails table) I have 2 employee record details,
These 2 employees (their names will be displayed on the DataGrid)
When I click on the first employee name on the DataGrid cell to display his/her details
When I click on the second employee name on the DataGrid cell to display his/her details etc. etc...

Could someone please view the code I provided below and tell me what am I doing wrong...

DataGrid xaml code:

XML
<DataGrid Height="490" HorizontalAlignment="Left" Margin="6,8,0,0" Name="GridViewEmployeeName" VerticalAlignment="Top" Width="200" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Background="{x:Null}" FontFamily="Verdana" FontWeight="Bold" FontSize="16" GridLinesVisibility="None" BorderBrush="Silver" RowDetailsVisibilityMode="Visible" CanUserResizeRows="False" ItemsSource="{Binding}" SelectionChanged="GridViewEmployeeName_SelectionChanged" SelectionMode="Single" IsSynchronizedWithCurrentItem="{x:Null}" CanUserResizeColumns="False" AutoGenerateColumns="False" HeadersVisibility="Column" EnableRowVirtualization="False" CanUserAddRows="False" RowHeight="22">
                        <DataGrid.Columns>
                            <DataGridTextColumn FontSize="12" FontWeight="Bold" Header="Employee Name" IsReadOnly="True" Width="200" Binding="{Binding Name}" CanUserResize="False" FontFamily="Verdana" />
                        </DataGrid.Columns>
                    </DataGrid>


C# code Window Load displaying only names of the employee in DataGrid

C#
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
            string CmdString = string.Empty;

            using (OleDbConnection conn = new OleDbConnection(ConString))
            {
                CmdString = "SELECT Name FROM EmployeeDetails";

                OleDbCommand comm = new OleDbCommand(CmdString, conn);
                OleDbDataAdapter sda = new OleDbDataAdapter(comm);
                DataTable dt = new DataTable("EmployeeDetails");

                sda.Fill(dt);
                GridViewEmployeeName.ItemsSource = dt.DefaultView;
            }
        }


C# code

C#
private void GridViewEmployeeName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Desktop\iPosSystem\iPosSystemMenu\iPosSystemMenu\DataBase\RestaurantMenu.accdb;Persist Security Info=False;";
            OleDbConnection conn = new OleDbConnection(ConnStr);

            string sql = "SELECT Name, NIN, Phone, Address, PostCode, City, JobTitle, AccessCode, AccessLevel, AssignTableAccess FROM EmployeeDetails";

            OleDbCommand cmd = new OleDbCommand(sql, conn);

            conn.Open();

            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                txtFullName.Text += dr["Name"].ToString();
                
                txtNIN.Text += dr["NIN"].ToString();
                
                txtPhoneNumber.Text += dr["Phone"].ToString();
                
                txtAddress.Text += dr["Address"].ToString();
                
                txtPostCode.Text += dr["PostCode"].ToString();
                
                txtCity.Text += dr["City"].ToString();
                
                JobTitleComboBox.Text += dr["JobTitle"].ToString();
                txtAccessCode.Text += dr["AccessCode"].ToString();
                
                AccessLevelComboBox.Text += dr["AccessLevel"].ToString();
                
                AssignTableAccessCheckBox.IsChecked = dr["AssignTableAccess"].Equals(true);
            }
            dr.Close();
            conn.Close();
        }
    }


Could someone help me on this please I'm new to WPF...

Kind Regards to everyone

Lapeci
Questionwpf ritchbox Pin
MemberDotNetting6-May-12 3:41
MemberDotNetting6-May-12 3:41 
AnswerRe: WPF RichTextBox Pin
Wayne Gaylard6-May-12 21:07
professionalWayne Gaylard6-May-12 21:07 
Questionadd wpf user control Pin
MemberDotNetting4-May-12 22:22
MemberDotNetting4-May-12 22:22 
AnswerRe: add wpf user control Pin
Abhinav S5-May-12 21:40
Abhinav S5-May-12 21:40 
QuestionWPF DataGrid cell click Pin
LAPEC4-May-12 1:06
LAPEC4-May-12 1:06 
AnswerRe: WPF DataGrid cell click Pin
Erik Rude4-May-12 1:31
Erik Rude4-May-12 1:31 
GeneralRe: WPF DataGrid cell click Pin
LAPEC4-May-12 1:51
LAPEC4-May-12 1:51 
GeneralRe: WPF DataGrid cell click Pin
Erik Rude4-May-12 2:46
Erik Rude4-May-12 2:46 
AnswerRe: WPF DataGrid cell click Pin
Jeremy Hutchinson4-May-12 2:46
professionalJeremy Hutchinson4-May-12 2:46 
Questionuser control Pin
MemberDotNetting3-May-12 13:40
MemberDotNetting3-May-12 13:40 
AnswerRe: user control Pin
Jeremy Hutchinson4-May-12 2:34
professionalJeremy Hutchinson4-May-12 2:34 
AnswerRe: user control Pin
Alisaunder6-May-12 2:23
Alisaunder6-May-12 2:23 
QuestionHow to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#3-May-12 4:02
Rocky#3-May-12 4:02 
AnswerRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Jeremy Hutchinson3-May-12 5:30
professionalJeremy Hutchinson3-May-12 5:30 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#3-May-12 20:42
Rocky#3-May-12 20:42 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Jeremy Hutchinson4-May-12 1:48
professionalJeremy Hutchinson4-May-12 1:48 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#4-May-12 3:05
Rocky#4-May-12 3:05 

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.