每个人都很难或者可能会这么做 [英] Difficult for each or maybe do-while

查看:60
本文介绍了每个人都很难或者可能会这么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我希望在数据绑定后自动在许多控件中输入值。

问题在代码块中的注释。

我知道我的方法不会工作但是我没有想法。



怎么样?



这是我的代码到目前为止:



Hi All,

I want to auto enter values in many controls after data-binding.
The problem is explained in the comments in the code block.
I know that my approach wont work but I am out of ideas.

how to??

this is my code so far:

private void dgvMydata_CellClick(object sender, DataGridViewCellEventArgs e)
       {
           List<Control> AllFoundControls = new List<Control>();

           int rowIndex = dgvMydata.CurrentRow.Index;
           foreach (DataGridViewCell cell in dgvMydata.CurrentRow.Cells)
           {
               if (cell.Value != null || string.IsNullOrEmpty(cell.Value as string))
               {
                   int columnIndex = cell.ColumnIndex;
                   string cName = dgvMydata.Columns[columnIndex].Name;
                   var fndControl = findControlByTag(cName);
                   if (fndControl != null)
                   {
                       Control foundControl = fndControl;
                       foundControl.Parent.Enabled = true;
                       foundControl.Enabled = true;
                       AllFoundControls.Add(foundControl);

                       string propertyName = "";
                       if (foundControl is TextBox) propertyName = "Text";
                       if (foundControl is CheckBox) propertyName = "CheckState";
                       if (foundControl is ComboBox) propertyName = "SelectedItem";
                       BindField(foundControl, propertyName, tableMydata, cName);//new databindings
                   }
               }

           }
           foreach (Control found in AllFoundControls)// or maybe Do While ????
           {
               //This is what I want to do:
               if (found.Focused)
               {
                   SendKeys.SendWait("{ENTER}");
                   //Wait until nextcontrol has focus( next control is focussed by program,
                   // and not always the next control in AllFoundControls
               }
           }
       }

推荐答案

首先,阅读ThePhantomUpvoter的评论。

First of all, read ThePhantomUpvoter''s comments.
ThePhantomUpvoter写道:
ThePhantomUpvoter wrote:

坦率地说,你想要做的事情没有多大意义。

Quite frankly what you are wanting to do does not make much sense.



我同意他的意见。



我们不明白你想要实现的目标......为什么要通过控制集来处理并仅在数据绑定输入按键事件?为什么要在 CellClick 事件中执行此操作?



可能您的问题定义为:我不知道怎么改变previ ous在表单中输入数据并以相同的顺序处理输入,所以...在您的情况下,使用 do .. while for(each)... next ,什么都不做!



您需要重新考虑并重新设计您的应用程序。


I agree with Him.

We do not understand what you''re trying to achieve... Why to process through the collection of controls and binds data only on "Enter" key press event? Why to do that in CellClick event?

Probably, your problem is defined as: i do not know how to alter previous entered data in a form and process the input in the same sequence, so... in your case, using do.. while or for (each)... next, changes nothing!

You need to rethink and redesign your application.


这篇关于每个人都很难或者可能会这么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆