Я разработал приложение для выставления счетов и добавил в свой WPF-приложение Usercontrol с более чем 2 текстовыми полями. Я использую опцию поиска в itemcode для textbox1, а itemname, показывающий textbox2 для получения значения из данных базы данных, успешно отображается, Теперь мне нужно текстовое поле, как динамически добавлять в Usercontrol и сосредоточиться на следующей строке, если заполнить 1 строку, а затем сосредоточиться на следующей строке. Пожалуйста, найдите код ниже, что я сделал ошибку в приложении, пожалуйста, помогите мне друзья. Спасибо за продвижение
**Usercontrol.xaml**
<UserControl x:Class="InvoiceApp.UserControltest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="250" d:DesignWidth="560" VerticalAlignment="Top" Loaded="UserControl_Loaded">
<Grid x:Name="ItemHolder" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="250" Width="560">
<TextBox x:Name="txtbx1" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top" Width="111" KeyDown="txtbx1_KeyDown" BorderBrush="#FFC5C7CB" />
<TextBox x:Name="txtbx2" Height="20" HorizontalAlignment="Left" Margin="110,0,0,0" VerticalAlignment="Top" Width="92" BorderBrush="#FFC5C7CB" />
<TextBox x:Name="txtbx3" Height="20" HorizontalAlignment="Left" Margin="201,0,0,0" VerticalAlignment="Top" Width="85" BorderBrush="#FFC5C7CB"/>
<TextBox x:Name="txtbx4" Height="20" HorizontalAlignment="Left" Margin="285,0,0,0" VerticalAlignment="Top" Width="85" BorderBrush="#FFC5C7CB" />
<TextBox x:Name="txtbx5" Height="20" HorizontalAlignment="Left" Margin="369,0,0,0" VerticalAlignment="Top" Width="85" BorderBrush="#FFC5C7CB" />
<TextBox x:Name="txtbx6" Height="20" HorizontalAlignment="Left" Margin="453,0,0,0" VerticalAlignment="Top" Width="78" BorderBrush="#FFC5C7CB" />
<TextBox x:Name="txtId" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top" Width="22" Margin="536,1,0,0" BorderBrush="#FFC5C7CB" />
</Grid>
</UserControl>
**Usercontroltest.cs**
private void txtbx1_KeyDown(object sender, KeyEventArgs e)
{
TextBox txtbx = (TextBox)sender;
if (e.Key == Key.Enter)
{
SqlCommand cmd = new SqlCommand("Select * from tbl_Tax WHERE Tax=@tax", InvoiceApp.FrmBill.con);
cmd.Parameters.AddWithValue("@tax", txtbx.Text);
// SqlDataReader dr = cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
txtbx2.Text = ds.Tables[0].Rows[0]["Id"].ToString();
// txtbx3.Text = dr[3].ToString();
txtbx3.Text = ds.Tables[0].Rows[0]["Tax"].ToString();
txtbx4.Text = ds.Tables[0].Rows[0]["TaxAmount"].ToString();
txtbx5.Text = ds.Tables[0].Rows[0]["Description"].ToString();
// txtbx6.Text = ds.Tables[0].Rows[0]["Description"].ToString();
// txtId.Text = ds.Tables[0].Rows[0]["Id"].ToString();
Items.Rows.Add(txtbx2.Text, txtbx3.Text, txtbx4.Text, txtbx5.Text);
// dataGrid1.ItemsSource = Items.DefaultView;
//dataGrid1.DataContext = Items;
// dattt();
}
//if (grdQustion.Rows.Count >= 1)
//{
// int i = grdQustion.CurrentRow.Index + 1;
// if (i >= -1 && i < grdQustion.Rows.Count)
// grdQustion.CurrentCell = grdQustion.Rows[i].Cell[0];
//}
}
ds.Dispose();
}