|
You excplains pretty nice Chris =)
int result = 0;
foreach (ListViewItem lvi in listView3.Items)
{
result += (lvi.SubItems[4].ToString()) * (lvi.SubItems[5].ToString());
}
label12.Text = result.ToString();
it says: Error1Operator '*' cannot be applied to operands of type 'string' and 'string'
can´t i use * in that order?
What do should i do??
-- modified at 19:56 Friday 7th September, 2007
|
|
|
|
|
result += (float)(lvi.SubItems[4].Text) * (float)(lvi.SubItems[5].Text);
And also note that result should now be a float, not an int. I didn't even consider that you were using "," as the decimal separator. I am so used to using ".", that I didn't even consider the alternative. Sorry for the confusion.
-Jeff
|
|
|
|
|
i need to get a cell value from each of the selected datagrid rows. i will then put these values in a t-sql delete from statement. i can't seem to find any clear direction on how to loop through a selected set in a datagrid and then get a particular cell value. any re-direction, or comments would be greatly appreciated.
look out, noob wreck'n havoc
|
|
|
|
|
I believe it's a case of doing something like
foreach(DataGridRow row in grid.Rows)
{
string field = row["columnName"].ToString();
string orThisWay = row[0].ToString();
}
You can cast to string, if it's a string, or use the 'as' operator ( better ), but tostring will always give you some sort of string.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I can't use DataGridRow due to the protection level.
I did try this though, which works for a single selected row (now to iterate this through all the selected rows???):
int delRow = (int)dataGrid.CurrentCell.Value;
_connStr = this.getDBConnection("net");
SqlConnection conn = new SqlConnection(_connStr);
string sql = "delete from gisLinkedDocument where LinkKey in (@delRow)";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter parm = cmd.Parameters.Add("@delRow", SqlDbType.Int);
parm.Value = delRow;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{
MessageBox.Show("The link was NOT deleted");
}
finally
{
if (conn.State != ConnectionState.Closed)
conn.Close();
}
look out, noob wreck'n havoc
|
|
|
|
|
I belive you can do something according to:
List<int> selectedRowIndexes = new List<int>();
foreach(DataGridViewRow row in dataGrid.SelectedRows)
{
selectedRowIndexes.Add(row.Index);
}
... code for deleting the indexes ...
Happy coding!
-Larantz-
-- modified at 18:00 Friday 7th September, 2007
Fixed missing <> for the generic list.
|
|
|
|
|
Ups.
I wrote it as generic but I forgot to tick the 'Ignore Html'...
I'll fix it now.
-Larantz-
|
|
|
|
|
How do i login by a streamreader .txt file..?
when:
textbox1.text(username)
textbox2.text(username)
.txt file are build like this
#
username
password
Tnx All!!;)
|
|
|
|
|
your question is missing a lot of details. File.ReadAllLines ( from memory ) returns a string array from your file, so that's a good way to get out your username and password, is that the bit you're stuck on ? Log on to where ? What do textboxes have to do with it ? Is there a typo in your post, is the second textbox the password ? They are surely not named that ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
no that´s just an example..
On a button_click event
string q = textBox1.Text;
string w = textBox2.Text;
string[] lines = System.IO.File.ReadAllLines(".txt");
Int32 index = 0;
while (lines.Length >= index + 10)
{
if ("#" != lines[index].Trim())
{
index++;
continue;
}
String username = lines[index + 0];
String password = lines[index + 1];
index += 1;
if (q = username && w = password)
something like this.. but its wrong, how do i start a search on textbox1.text on row0 and textbox2.text are gonna be below.. or something???
tnx ;);P
-- modified at 12:47 Friday 7th September, 2007
|
|
|
|
|
Hi all,
I have a .h file written in c++ that contains the dfinition for some chip's registers.
how can I use this file in c# to avoid rewriting the same definitions again in C#.
Thank you
|
|
|
|
|
Hi,
AFAIK you can't use header files in C#.
What you can do is define a C# struct and give it the right attributes to make
sure the order is preserved, padding does not occur, etc.
How do you plan on accessing your chip from C#? Wouldn't that require some
native code, hence C/C++ anyway? So why do you need the registers at the C# level??
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the response,
I need to access these from the PC side cause these register values are controlled by user, and it woud be nicer to let him address regsters using their names and not the address value
|
|
|
|
|
You could use C++/CLI to aggregate the native structure in a managed class.
|
|
|
|
|
I'm working on WPF project in which I need to implement ZoomIn / ZoomOut on Scrollviewer object with seperate pan zoom window. There are two types of transformation which can be applied i.e. Layout Transform & Render Transform. Now the problem is I want to use the best of both kind of transformation.
I have a pan zoom window which shows the view of my scroll viewer object.When the view of my scrollviewer object changes i notify to pan zoom window to reflect the view of scroll viewer object.
For transformation, scrollviewer object's three properties are important. ViewPortSize, ExtentSize and Offset. When ZoomIn is performed, ViewPortSize and ExtentSize remains same in both Layout and Render transformation while Offset value gets changed in layout transform but in Render transform scrollviewer object's offset value is not changing. Because of this in render transform, even if the view(or layout) of my scrollviewer object in main canvas has changed still I can not send the changed information to pan zoom window (as offset value is same).
So my problem is my ZoomIn / ZoomOut related requirements are perfectly satisfied using Render Transform but if I use Render transform I can not update my view in Pan Zoom Window. Can any one suggest me the work around for this problem.
(I want to implement the zooming in the same way as implemented in Microsoft Visio. Pressing ctrl key n mouse wheel move wil provide the zooming operation in visio)
Below I'm pasting one link in which the problem described is I think somewhat related to my problem.
https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=991579&SiteID=1[^]
Hope I have been able to put up my question in proper way. Pls revert back in case more clarification needed. Thanks in advance.....
|
|
|
|
|
In the book I'm reading there is only explanation about RadioButtons.
Are there multiple choice button class somewhere? whats the name?
I basically need this to ID data I want to delete from a textfile.(to know which line to delete)
any tips how do I do it? I read something about datatables and grids, is that related to what I want to do? where can I find how those classes work?
|
|
|
|
|
CheckBoxes are designed to have a checked, unchecked, intermediary states. But it depends on the framework/IDE for how to set the state settings.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi guys,
I have the following code in my C# application calling a C++ dll. Please advice if this is a correct way to use a struct.
public struct pTest
{
public StringBuilder Raw;
public StringBuilder trn;
public StringBuilder ece;
public StringBuilder Ct;
public StringBuilder At;
}
[DllImport("c:\\Parser.dll")]
public static extern int Parse(string tst);
[DllImport("c:\\Parser.dll")]
public static extern pTest GetParseData();
#endregion
In my code when I call the functions, as follows
res=POSShare.UtilObj.Parse(stn);
POSShare.UtilObj.GetParseData();
I get the pinvoke error when I call the function. Please help?
sasa
|
|
|
|
|
You should be more specific. What error are you getting? Which function is generating error: is it Parse() or GetParseData()? How does your unmanaged struct look like?
|
|
|
|
|
Thank you Giorgi, Here is C++ dll code that I am trying to call.
typedef struct {
LPTSTR lpsRaw;
LPTSTR lpsTransit;
LPTSTR lpsAccount;
LPTSTR lpsCSN;
LPTSTR lpsAmount;
} LPMICR;
LPMICR (CALLBACK* GetParseData) ();
int (CALLBACK* ParseMICR) (LPTSTR lpStr);
Here is my C# code:
public struct pMICR
{
public StringBuilder Raw;
public StringBuilder Transit;
public StringBuilder Account;
public StringBuilder CSN;
public StringBuilder Amount;
}
[DllImport("c:\\Parser.dll")]
public static extern int ParseMICR(string Micr);
[DllImport("c:\\Parser.dll")]
public static extern pMICR GetParseData();
I am getting the following error: Method's type signature is not pinvoke compatible. This happens when I call getparse data function. Parsemicr function completes just fine.
Please advice.
sasa
|
|
|
|
|
Hi,
if the API is fixed, you will need more C# code to get the marshaling right.
I try to keep P/Invoke stuff as simple as possible, so...
if you can choose the API, I would simplify as much as possible; I suggest you
pass the StringBuilders one by one as parameters to the GetParseData function,
and have it return just some result code (int or bool).
Good practice is to pass the capacity of each of the StringBuilders too.
So it could look like:
[DllImport("c:\\Parser.dll")]
public static extern int GetParseData(StringBuilder Raw, int RawLen, StringBuilder Transit,
int TransitLen, ...);
The native code can accept the data as pointers and lengths, and is allowed to write
to the dereferenced pointer (within the limits of the StringBuilder's capacity, you
really must create them with a sufficient "initial" capacity, they won't be grown by
the native code!)
And if you feel the need to keep the results in a single struct, you could
create one (with strings) and load it from the StringBuilders once GetParseData() returns.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
I believe this is the second or third time you have come to my rescue, thank you for that.
yia I agree with you, unfortunately this dll is written by an outside source so I can't modify it. I have requested them to modify it. Hopefully they will do so. Either way you say that I would require more marshalling, what do you mean by that? how would I do it?
Please advice.
sasa
|
|
|
|
|
Hi,
assuming the native code is allocating the strings and just passing pointers to them through
the struct, then you should declare the struct as containing IntPtr, then use one of
the Marshal methods, such as Marshal.PtrToStringAnsi().
BTW some one should sone how free the native strings. What does the API say about that?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Have you tried decorating the struct with the StructLayoutKind attribute.
[StructLayoutKind.Sequential]
public struct pTest
{
public StringBuilder Raw;
public StringBuilder trn;
public StringBuilder ece;
public StringBuilder Ct;
public StringBuilder At;
}
I always knew that some day I would wake up in the morning and decide to live forever, or die in the attempt.
|
|
|
|
|
yes I have that already and it is still giving me the error. Thank you for your response either way.
sasa
|
|
|
|