How to get DataGridView cell value? - clr

I need to compare my array string with DataGridView cell value
string z = DataGridView->Rows[e->RowIndex]->Cells[1]->Value.ToString();
I'm getting a problem:
IntelliSense: expression must have class type

I figured out the answer if anyone else needs solution here it is
String^ z = System::Convert::ToString(Grid_Darbuotojai->Rows[e->RowIndex]->Cells[1]->Value);

Related

How to implement a ControlValueAccessor to convert a property from num to String and vice versa

I am attempting to bind a property of type num. But angular2 complains that the attempated conversion (num to string) is illegal. I have seen where ControlValueAccessor could be used but lacks the knowledge to do so?
<input type="number"
min = "0"
max = "120"
#yearsCtrl = "ngForm"
[ngFormControl] = "ageForm.controls['yearsCtrl']"
[(ngModel)] = "age.years"
id = "years">
Does anyone knows how to use a ControlValueAccessor to convert ngModel num (age.years) to String for display in the browser and convert String back to num for storage?
I don't really want to have to convert my model properties to string to accomplish this.
If you define the model field of the input as type num it works by default. int should be avoided in the browser anyway for values that are passed from the browser.

"Cannot subscript a value of type '[String]' with an index of type 'String'

I'm trying to display a dynamically updated array in a label using:
for i in result {
outputLbl.text = result[i].joinWithSeparator("\n")
}
However I get the error
Cannot subscript a value of type '[String]' with an index of type 'String'.
Any idea how I can fix this?
Note that when using the loop "header" for X in Y, you don't get the indices of Y, but the actual elements of Y. Judging from your error, results is an array of strings ([String]). Hence, i in you for loop represents---one by one---the elements in the String array results.
So, if you wanted to access the string elements one by one in the for loop above, you could use the approach in your example:
let result = ["Hello", "World"]
for myString in result {
// use each string element in some manner...
}
However, as you are using the array method joinWithSeparator(..), you should use, just as Leo writes in his comment above, this method directly on your array (and not their elements!)
let result = ["Hello", "World"]
outputLbl.text = result.joinWithSeparator("\n")
/* Hello\nWorld */
I think what you are doing here is trying to iterate through an array of string and then update a label that is in this case "outputLbl".Here you can do something like this
for i in result {
//result is array of strings.
// here i is individual element of result array
/* outputLbl.text = result[i].joinWithSeparator(“\n”)*/
//instead you can write
outputLbl.text = i.joinWithSeparator(“\n”)
}
The reason you are getting this error is as follows:
It seems you are confusing the type of i. The variable result is of type [String] which means it is an array of String types. By virtue of being an array, it must be subscripted with an Int, not a String. So something like result[0] or result[12] is valid, but something like result["hello"] is not valid. The variable i here is a String because it is a single element in an array of String types, which means that effectively, what you're trying to do by saying result[i] is something along the lines of result["hello"].
That having been said, the true solution to your problem is that the method joinWithSeparator(_:String) is not a String method but rather a Sequence type method. Which means it should be called on a Sequence like an object of type [String]. So what you should use is:
outputLbl.text = result.joinWithSeparator("\n")
What's going on here is the compiler is inferring i to be of type String since that's what result is. You should be more verbose in your naming conventions.
for specificString in result {
outputLbl1.text += "\n\(specifcString)"
}
EDITED for correctness.

Error get value null in Excel MVC ASP.NET

I am using the following:
using (ExcelPackage ExcelPackage p = new ())
To open the excel worksheet and getting the values ​​of the cells as follows
string ap = ws.Cells[Lin, 12].Value.ToString().Trim();
But when the cell is empty presenting me this error, as I do so that when the cell is empty it ternha the null value. Estrou needing grab values ​​from several cells having value or not.
You can test for a null value and substitute an empty string using code like this:
string strValue = Worksheets.Cells[2,5].value==null ? string.Empty : Worksheets.Cells[2,5].value.ToString();
example
string ap = (ws.Cells[Lin, 12].Value??"").ToString().Trim();

How can I convert a string to a char array in ActionScript 3?

How do you convert a string into a char array in ActionScript 3.0?
I tried the below code but I get an error:
var temp:ByteArray = new ByteArray();
temp = input.toCharArray();
From the error, I understand that the toCharArray() function cannot be applied to a string (i.e in my case - input). Please help me out. I am a beginner.
I am not sure if this helps your purpose but you can use String#split():
If you use an empty string ("") as a delimiter, each character in the string is placed as an element in the array.
var array:Array = "split".split("");
Now you can get individual elements using index
array[0] == 's' ; array[1] == 'p' ....
Depending on what you need to do with it, the individual characters can also be accessed with string.charAt(index), without splitting them into an array.

Help With pattern matching

In my code I have to match below 3 types of data
abcd:xyz:def
def:xyz
xyz:def
where "xyz" is the real data and other part are Junk data. Now, for first 2 types as below I can split with ':' and can get the array[1] position data ... which will give me the correct one.
abcd:xyz:def
def:xyz
I am not getting How can extract the 3rd case. Any idea? Please help.
Thanks,
Rahul
string case1 = "abcd:xyz:def";
string case2 = "def:xyz";
string case3 = "xyz:def";
string result1 = case1.Split(':')[1];
string result2 = case2.Split(':')[1];
string result3 = case3.Split(':')[0];
If I understand your question correctly.
Use array[0] instead of array[1] in the third case after splitting.

Resources