|
Hi! I have a listview, let's say with 4 columns, with fullrow selection.
When i select one row, i want to get the element from the second column.
Can you tell me how to do that?
I know how to get the element from the first column, but to get the other element's of the row selected is kind of a problem for me.
Thanks!
|
|
|
|
|
|
How to use C++ style cast ( reinterpret_cast ) in C# ???
In C++ context :
NMHDR* pNMHDR;
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
Please give me the answer.
Thanks.
trannampro@yahoo.com
|
|
|
|
|
There are no special casting operators in C# like static_cast, dynamic_cast or reinterpret_cast. Just use the normal casting operator, like
void SomeFunc(object obj)
{
MyType t = (MyType) obj;
}
Just remember that the CLR will never allow type casts that violate casting rules, so you really cannot simulate the effect of reinterpret_cast in C# or any .NET language.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
In addition to the previous answer you can also use the as keyword.
The cast operator will throw an exception when the conversion is not possible, with as you'll get a null reference.
For example:
void MyFunc(object o)<br />
{<br />
MyType t = o as MyType;<br />
if (t == null)<br />
}
Regards,
mav
|
|
|
|
|
How to convert int/long to string and string to long in C#?
thanks.
|
|
|
|
|
string 2 long
Convert.ToInt64(stringvalue);
long 2 string
string strlongvalue = longvalue + "";
You can use the Convert class voor a lot of conversions.
Good luck.
No hurries, no worries.
|
|
|
|
|
You mean:
int i0 = 777;
long l0 = 999999;
string kk = i0.ToString();
string kk2 = l0.ToString();
and
int i1 = Convert.ToInt32(kk);
long l1 = Convert.ToInt64(kk2);
Bye...
|
|
|
|
|
Hello there
I am new in CSharp coming from vb.net I have couple of things to ask
which are available in vb.net and what are their alternatives in CSharp ?
1. val(textbox1.text) in vb.net = ??? in csharp
which converts like blank string "" to 0 I used convert function but it does not convert "" to 0
2. How to get the error number err.number
in CSharp i did this
catch (Exception ex)
{
// ex gives the message not the error number
// need to know the error number here
}
3. Module in vb.net which you can add in project for the collection of global functions and variables = ______ in CSharp ????
I added codefile but could not add global variables in it
thanks alot for the support
|
|
|
|
|
I'm afraid it's not possible to do what you want in C#.
(1) is fairly easy. This piece of code will do it for you
int ConvertToInt(string text)
{
if (text == null || text.Length == 0) return 0;
return Int32.Parse(text);
}
(2) is not possible, AFAIK.
(3) is not possible at all in C#. C# doesn't support global variables.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Rizwan Bashir wrote:
I added codefile but could not add global variables in it
C# does not support global variables. You could create a class with public static fields, and it's the same effect. But I'd recommend you to design your app so you don't require them.
class Globals
{
public static MainForm mainForm;
}
MessageBox.Show(Globals.mainForm, .....); -- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Rizwan, what you're asking here is not how to transfer functions from VB.NET to C#, it's about legacy VB functions.
These don't have an equivalent in C#.
1) But Val() can be implemented as stated above by someone else.
2) The kind of error handling in VB is disencoraged in .NET.
You have a lot more powerful exception handling mechanisms, so you shouldn't go for a On Error Resume Next (YUCK!) anymore.
3) There are no global variables. Period. You can use static (shared in VB.NET) class members for this purpose.
Regards,
mav
|
|
|
|
|
Mav, Your point is well taken as I also know that on error resume next type of statements are discouraged and even I am using try catch in vb.net. the problem was.... I am building multi-lingual application with ability to add more languages at run time. so I have to give custom messages according to language selected. for which I need err.number.. but any ways I solved the problem by throwing the exception with the number and in exception I am treating that message as numeric value to process further.
any ways thanks alot to all of you for helping me out.... and I might keep on bothering you more for issues in next couple of days before getting used to with it...
|
|
|
|
|
i want to make my button_click event to open an .exe file (without open file dialuge Box)
misho
|
|
|
|
|
Take a look here[^].
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hello,
I'm totally new to distributed applications and i need help with:
- How do i expose C# windows service procedures so the they can be called remotely??(or is it the same as declaring procedures normally and just adding a referece to the windows service??)
- Learning how to tell when Remote Procedure Call's are made to a C# windows service so that the procedure executes using the parameters supplied.
thanks,
Afzal Hassen
|
|
|
|
|
A bit trifle to the experienced, this question probably is!
Say one is building a multi tier application:
web-front
business-logic
database
Going backwards:
1 - user clicks to get some info from the database.
2 - request is handled on the server
3 - business object is instantiated to process the request
4 - data access object is instantiated to retrieve the data
5 - user satisfied.
So the questions are:
1. Does 3 and 4 happen every time? The objects get instanciated? Or should the object be maintained in memory for the next call?
2. The data retrieved (dataset or should I say view) contains a lot more info (is complete in other words) before the business logic is applied. Shouldn't this dataset persisted in some way to be reused instead of making expensive calls to the database?
Now I may have the lines between the tiers wrong. So can someone elaborate?
A practical example would be nice (not code just pseudo).
|
|
|
|
|
Anonymous wrote:
1. Does 3 and 4 happen every time? The objects get instanciated? Or should the object be maintained in memory for the next call?
Depends on how much memory those object consume and how expensive it is to create/destory them. And another thing to take into consideration is the number of time this will happen. If you have a busy website with a lot of user requests then it would make sense to persist something on the backend for a while. On the other hand if you only have a handful of request then its safe to keep on recreating them. Recreating them is also safers because your object will not retain state from a revious request and chances are much smaller that things will get stale since you are working on a freshly created object. Besides with the speed on modern hardware you should not encounter any problems constantly recreating and destroying objects.
Anonymous wrote:
2. The data retrieved (dataset or should I say view) contains a lot more info (is complete in other words) before the business logic is applied. Shouldn't this dataset persisted in some way to be reused instead of making expensive calls to the database?
Calls to the database are not that expensive anymore. Correction, if you know to use the right way to access the right database then this operation is not that expensive. For example; if you use a SQL Server as your database then you should use the SqlConnection, SqlCommand and SqlDataReader object to work with it. By using these objects the developers at Micosoft guarantee that you will have the fastest means of accessing data from the database. If you use an OdbcConnection, OdbcCommand and OdbcDataReader, even though SQL Server will understand your request, the results will be slower then by using the native Sql* objects.
Also there is a big difference between a DataSet and a DataReader. When reading data from a database through a web application it is very rare you would use a DataSet. DataSets can be slow and can require a lot of memory because a DataSet will read all the data from your database and keep eveything retrieved in memory. I would recommend using a DataReader instead. DataReaders don't create a local copy of the data you requested in local memory because they keep an open connection to the database and only retrieve data that you need at the moment. A really good article about this subject can be found here:
http://aspnet.4guysfromrolla.com/articles/050405-1.aspx
|
|
|
|
|
Excellent Article indeed! Appreciate the suggestion.
So data reader is the way to go unless it is absolutely necessary to use a dataset. On a tangent, this is also true for reading xml using the pull model in the framework with XML reader instead of loading the XMLDocument in memory.
I had also hoped that someone would put this scenario into multi-tier model for me, as I am still confused as where the separation is. For example, my aspx page will have the code-behind page - is this where I would type in my queries and interact woth my data-reader/dataset and process them or would I use pre-written classes(containing the logic for quering the data) and pre-defind methods like "get-product-by-id" etc., which I would instantiate in the code-behind page and pass the parameters to be processed withing those objects and return the results? Guess I am after "best-practices" here in designing a web-application that is scalable and reusable.
Furthermore, everyone of those objects (like dataset/datreader/adapter) are objects already, so is wrapping them necessary?
If someone can put this in perspective or suggest an article, I would appreciate it. Googling brought in results that are either too simplistic or too thoretical.
And Thanks Peter for taking the time to explain.
|
|
|
|
|
Hi buddies,
How to get the video srteaming details of an user from Flash communication server using C#?
is it possible???
it is very urgent...please help with a sample code or any article..
Thanks,
Vinu
|
|
|
|
|
Hi there,
I'm just wondering is there anyway possibly about windows control's events make happen in code? Not in Form..
As if it is user click button on form during the execution of code
Just like custom event make it happen ... or some other ways?
private void doSomething()
{
//Some code...
btnButton.Click(null,null);
}
|
|
|
|
|
Always you have a windows control's event you have a delegate function.
Try to call the delegate.
this.btnButton.Click += new System.EventHandler(this.btnButton_Click);
...
private void doSomething()
{
...
btnButton_Click(null, null);
...
}
Is that you want?
|
|
|
|
|
nope.. I already got solution..
btnButton.PerformClick()
Thanks anyway..
|
|
|
|
|
Hi
I wand to develop a tri state Check listed box (That allows tickboxs to be in three states: ticked, unticked and crossed.) for a win form application.
There is no such control in the .Net,
shall any one suggest how to do or shall I get any sample code for the same.
Regards
|
|
|
|
|
Given that you need to draw and store three states ( and it's a pretty simple control ), I'd be inclided to create an enum for the state and derive a control from the absolute base class, and handle all events and drawing myself. Then I'd be inclined to write a CP article when I was done
Christian Graus - Microsoft MVP - C++
|
|
|
|