リストボックス内で、リストボックスアイテムをダブルクリックすると、リストボックスアイテムの値がリストボックス内のダイナミックテキストボックスに割り当てられます(ダイナミックテキストボックスをリストボックス内に作成しました)。クリックしてEnterキーを押すと、テキストボックスの値がリストボックスの項目に追加され、次にdynamictextboxが削除されました.ESCキーをクリックすると、リストボックスの項目に初期値が追加されます。wpfでKeyEventArgsメソッドを呼び出す方法
私はMouseEventArgメソッドの内部でkeyeventArgsメソッドをどのように呼び出すことができるかに問題があります。
C#
System.Windows.Controls.TextBox dynamicTextBox = new System.Windows.Controls.TextBox();
string previousvalue;
private void items_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Get the index value
var index = lstbxindex.Items.IndexOf(lstbxindex.SelectedItem);
//set the textbox height and width property
dynamicTextBox.Width = 230;
dynamicTextBox.Height = 50;
//Add a textbox to the listbox
this.lstbxindex.Items.Add(dynamicTextBox);
//To assign the selectedITem values to textbox
dynamicTextBox.Text = lstbxindex.SelectedItem.ToString();
//Get the textbox values before editing
previousvalue = dynamicTextBox.Text;
//Remove the values from the listbox item
lstbxindex.Items.RemoveAt(index);
dynamicTextBox.AcceptsReturn = true;
}
private void checkenterclicked(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
EnterClicked(sender, e);
//dynamicTextBox.PreviewKeyDown += EnterClicked;
}
}
private void EnterClicked(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
using (DatabaseConnector databaseConnection = new DatabaseConnector(ApplicationConstants.ConnectionString))
using (ProjectsTable projectsTable = new ProjectsTable(databaseConnection))
{
//Here Filter the Name from project Table which DbActive state is zero
projectsTable.AddFilter(new Filter<ProjectsColumnTypes>(ProjectsColumnTypes.DbActive, CompareOperator.Equals, true));
projectsTable.Read();
projectsTable.AddFilter(new Filter<ProjectsColumnTypes>(ProjectsColumnTypes.Name, CompareOperator.Equals, dynamicTextBox.Text));
projectsTable.Read();
foreach (DtoProjectsRow row in projectsTable.Rows)
{
//Guid DbId = row.DbId;
Guid DbId = row.DbId;
var UpdateRow = projectsTable.NewRow();
UpdateRow.Name = dynamicTextBox.Text;
UpdateRow.DbId = DbId;
UpdateRow.DbActive = true;
// Alter the row to the table.
projectsTable.AlterRow(UpdateRow);
// Write the new row to the database.
projectsTable.Post();
//Add the items in comboBox
lstbxindex.Items.Add(dynamicTextBox.Text);
}
// dynamicTextBox = e.Source as System.Windows.Controls.TextBox;
}
}
else
{
if (e.KeyCode == Keys.Escape)
{
lstbxindex.Items.Add(previousvalue);
lstbxindex.Items.Remove(dynamicTextBox);
}
}
}
一部の値をテキストボックスに編集したいとします。いずれかのキーが押されるとヒットします – user688
@LogeswariJegatheesanはい、Enterキーのみをフィルタリングするため、他のタイプのキーは無視されます。 (DatabaseConnector databaseConnection = new DatabaseConnector(ApplicationConstants.ConnectionString)) –
ありがとうございます。それは働いています。 – user688