English 中文(简体)
A. 阵列中的文字箱价值
原标题:Textbox values to array

i 浏览几个文本箱,如果它们含有价值,如果它们有价值的话,我想通过这些箱子检查。

The textboxes are called txtText1, txtText2....txtText12. This is what I got so far:

for (int i = 1; i < 13; i++)
{
   if(txtText[i] != String.Empty)
    {
        TextArray[i] = Convert.ToString(txtText[i].Text);
    }
}

不允许使用txtText[i]。

我如何通过这些箱子?

最佳回答

理想的做法是,将它们放在一个阵列上,而不是使用几个不同的变量。 基本上,你们想要收集文字箱,正确吗? 因此使用收集类型。

页: 1

TextBox tb = (TextBox) Controls["txtText" + i];

assuming their IDs have been specified correctly, but personally I would use the collections designed for this sort of thing.

问题回答

Assuming the txtText array contains references to TextBox objects you can do this

var textArray=txtText.Where(t=>!string.IsNullOrEmpty(t.Text)).Select(t=>t.Text).ToArray();

我不认为你能够像设计者那样制造阵列物体。

您可以做的任何工作:您可以编造一个类别变量:IE amountable<Text Box>_text Boxes,并填写在构造中的所有文本框。

之后,你可以做些什么。

foreach(var textbox in _textboxes)
{
    Console.WriteLine(textbox.Text); // just an example, idk what you want to do with em
}

你们可以这样做。

List<string> values = new List<string>();
    foreach(Control c in this.Controls)
    {
        if(c is TextBox)
        {

            TextBox tb = (TextBox)c;
            values.Add(tb.Text);
        }
     }
     string[] array = values.ToArray();

a. 编制一个文本箱而不是像阿雷拉这样的文件:

List<TextBox> myTextboxList = new List<TextBox>();
myTextBoxList.Add(TextBox1);
myTextBoxList.Add(TextBox2);
mytextBoxList.Add(TextBox3);

接着,每一件物品一度使用:

Foreach (TextBox item in myTextboxList) {
    // Do something here, for example you can:
    item.Text = "My text goes here";
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签