|
hi,
easy way is give dateTime as string Format..
ex:-
DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")
Now No need to worry when local time and sqldbtype is different.
regards,
pubudu.
|
|
|
|
|
Hello,
In Windows Forms, I have a datagrid that is sortable by clicking on the column headers.
Say 2nd record is already selected and I sort the datagrid.
Now the previously selected row is unselected. At this point how do I get the index to this previously selected row to have it selected again.
Thank you.
|
|
|
|
|
In the sort event ,Just before the sorting itself ,take that value and put it in any other field and then retrieve it when you want.
|
|
|
|
|
Sorry but I have no clue what you are referring to!
What sort event? There is no sort event. There is only an event called ListChanged in the datagrid's dataview that fires on (and not before) sorting the datagrid. Another thing is, the dataset still has the same indexing order on the datagrid, meaning, a particular row's index before or after sorting remains intact eventhough after sorting it's position on the datagrid has changed.
|
|
|
|
|
Hi,
I have a possible solution for you - it has a couple of drawbacks, but might help.
This example assumes that you have a DataGrid called dataGrid1, who's DataSource is a DataTable called dt.
It also assumes that you've declared an ArrayList called al.
First of all, set the "AllowSorting" property of dataGrid1 to "false" - you have to sort it manually.
Then add the following event handler code (don't forget to wire it up to dataGrid1's DataGrid1MouseDown event in the Properties Grid).
void DataGrid1MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if(e.Button == MouseButtons.Left)
{
if (hti.Type == DataGrid.HitTestType.ColumnHeader)
{
DataColumn dc;
dc = dt.Columns[hti.Column];
al = new ArrayList();
for(int i = 0; i < dt.Rows.Count; i++)
{
if (dataGrid1.IsSelected(i))
{
listBox1.Items.Add(dt.Rows[i][0].ToString());
al.Add(dt.Rows[i][0].ToString());
}
}
SortData(dc.ColumnName);
}
}
}
This has basically saved the column1 contents of each selected row in an array, so we can later "re-select" the correct rows.
Now add the following code for the SortData method.
private void SortData(string colname)
{
DataRow[] drarray;
drarray = dt.Select(null, colname,
DataViewRowState.CurrentRows);
int len = drarray.Length;
for (int i = 0 ; i < drarray.Length ; i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
dr[j] = drarray[i][j];
}
dt.Rows.Add(dr);
}
for (int i = len - 1 ; i >=0 ; i--)
{
dt.Rows.RemoveAt(i);
}
for (int i = 0; i < dt.Rows.Count; i++)
{
if (al.Contains(dt.Rows[i][0].ToString()))
{
dataGrid1.Select(i);
}
}
}
This sorts the original DataTable into an array, adds the sorted records to the end of the DataTable, then deletes the original ones.
It then checks each row in the DataTable, and if the data in column1 matches the saved data in the ArrayList, it marks the corresponding rows in the DataGrid as "Selected".
Therefore, multiple selected rows are supported.
Limitations:
1. It only supports ascending sorts.
You might want to build a better sort using an IComparer
interface.
2. You lose the little arrows on the column headers.
3. It assumes that the data in Column1 of the DataTable is unique.
You could combine data from more than one column to create a
unique key.
Hopefully this will help get on the right track.
Good luck!
Gary Perkin.
PS I think the Sort Event that the previous respondent was referring to is available in WebForms, but I may be wrong...
|
|
|
|
|
Thank you very much for taking the time to reply.
This is a good start. I think if I replace datatable with dataview I could get it sorted both ways...
Still, I don't understand the usefulness of ability to sort via clicking on column headers, unless you don't want to select a row.
|
|
|
|
|
how can i transfer the data between different forms if that data is created in one form and i need to transfer it to another form within the same application .
Miss With The Best And Die Like The Rest
|
|
|
|
|
I have tried to answer this question on your previous post. There are many ways to achieve what you are trying. First of all, a form is a class like any other ordinary class. Say you have a textbox named text1 which is declared as public within your class Form1 and you use it for letting users write down their username. Then to send its value to a different class, named AnotherClass, from within class Form1 (which is the current form) you could say something like:
AnotherClass myClass = new AnotherClass();
myClass.userName = this.text1.text;
OR
AnotherClass myClass = new AnotherClass(this.text1.text);
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
i need to store some variables withing one class and that class to be accessible all over my application with the specified common variables as the following
i need when i press button to take the text value from the textbox.text and store that value in global variable within a class which i will use in different forms within the same application .
In addition i tried alot but each time when i declare my class as the following
globalclass myclass = new globalclass();
this.username = myclass.username;
it gives me blank variable in username string
i guess that because i open new instance of that class
but i need to store variables and to be called whenever i want within my application with the variables stored in its places
Any help with that
Thanks .
Miss With The Best And Die Like The Rest
|
|
|
|
|
snouto wrote:
i need when i press button to take the text value from the textbox.text and store that value in global variable
I can't figure out what exactly you are doing wrong here. If you create a class with public variables or, even better, public properties, you shouldn't have problem using it across your forms and application. All you have to do is to create an object of that class and pass those members of it that you need to work with (or the whole object if you need it), as arguments to different classes across your application.
snouto wrote:
In addition i tried alot but each time when i declare my class as the following
globalclass myclass = new globalclass();
this.username = myclass.username;
it gives me blank variable in username string
What value do you initialize the username variable with? Also, what is this.username for? Do you wish to refer to a textbox on the form?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
my friend i need to store the text box value into
the form username string which i declared in the class of the main form i need that username to be stored in the global class to be accessible with the value of the variable all over my application in different forms
Globalclass myclass = new Globalclass();
myclass.username = textbox.text;
and that myclass.username can be accessed from the globalclass in another form
Miss With The Best And Die Like The Rest
|
|
|
|
|
Ok, so what you are saying is that no matter what you type into the textbox, all you keep getting copied into myClass.Username is an empty string? In what event did you place this code?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
please add me to your contact list
my email address is
matrix_623@yahoo.com
please add me and chat with me now on yahoo please iam waiting for you my friend
Miss With The Best And Die Like The Rest
|
|
|
|
|
The way to this is to :
Create a new class called GlobalVariables //for example.
And then add static members in it and just do:
//in global .
static string userName = "";
//In your form.
button1_Click()
{
GlobalVariables.userName = this.userName.Text;
}
//And just access it as easy as :
string reciever = GlobalVariables.userName;
without the need to initialize any thing.
|
|
|
|
|
The key to what you need is a concept of "static" members.
static members are those that are shared among all instances of a class and are declared using the static keyword.
You can access these static members by just using the classname of the containing class, instead of the variable name holding an instance for instance members.
You can even initialize these static members in the static class initializer that's executed when the class is first loaded by the CLR.
For example:
class MyGlobals
{
static string UserName;
static DateTime LogonTime;
static MyGlobals()
{
UserName = "Not set";
LogonTime = DateTime.MinValue;
}
} Then you can simply do this:
class MainProgram
{
public static void Main()
{
Console.WriteLine("Username is " + MyGlobals.UserName);
}
} This will give you "Not set" without any previous initialization in your MainProgram class.
Regards,
mav
|
|
|
|
|
Its a common situation.
Everybody is giving you advices like "make this field and property that static".. And its OK. But thinking in global I think you should use "Singleton pattern". That would be the most clear solution.
Best regards
p.p: What you mean with "Miss with the best".. wasn't it "mEss"?
|
|
|
|
|
I currently have a Server/Client setup using Asynchronous trasnferring of messages. I now want to add the ability for a client to send a file to the server, who then passed it to the client. I assume the best way to do this is using the existing Asynch model, but I might be mistaken. Anyone have any advice as to what would be the best/easiest way?
|
|
|
|
|
hi man how are you
please Add me to your yahoo contact list cause iam developing the same application and i did alot of progress and i want you to join me i had already did
1) multithreaded server .
2) multiple user connection.
3)login for users using database MS Sql 2000
4)Private chatting
5)General chatting
6)Webcam Broadcasting .
7)File transfer Options
//Sound is on the way so if you want to share with me the knowledge add me and you will be partner with me in my application thank you
Yours;
Snouto Override ......
Miss With The Best And Die Like The Rest
|
|
|
|
|
Hello!
I'm developing a windows service that is monitoring the filesystem, i need to make it write to a log BEFORE you open a file that the file is beeing opened. I can catch file change,rename,delete,create event, but i can't find anything for catching a "about to be opened" event. Anyone got suggestions?
|
|
|
|
|
In the event handler of the openning Write a call to a method that do this and when this method says that to the user, it will return and open the file.
|
|
|
|
|
hmm i'm not sure i understand.. i need to catch the event before the user opens any file in thefilesystem, to a service.. but from what i understand there is no such event in the api..
|
|
|
|
|
There is no "Opening" event.
Believe it or not, you'll have to write a file system driver. This is best done in C++ because of the HUGE amount of COM Interop your going to have to do in C# to get this to work. If done in C#, this will add quite an overhead to all file operations system-wide.
SysInternals FileMon does just this. You can find it here[^] with a short decsription of what it does and how. This is not easy if you don't know anything about HTFS internals, and as a side-note, will require you to get the Windows Device Driver Development kit which is only downloadable by MSDN subscribers. You can get it on CD though for a small fee.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need to show the network performance just like Windows Task Manager’s Network Utilization. I am using PerformanceCounter class. It is working fine until I deploy my application on any other machine.
My code goes like :
this.performanceCounter.CategoryName = "Network Interface";
this.performanceCounter.CounterName = "Current Bandwidth";
//Following line breaks
this.performanceCounter.InstanceName = "Realtek RTL8139 Family PCI Fast Ethernet NIC - Virtual Machine Network Services Driver";
The problem is that the VS.NET 2003 hardcodes PerformanceCounter.InterfaceName in my application. I want to get this ethernet driver name at runtime. How do I do it?
Zishan
|
|
|
|
|
I am implementing a webservice that link to a database on the server machine, The operation on SELECT function work alright. However, operation such as INSERT, DELETE doesn't work at all. Could any one suggest why? I have tried various ways of INSERTing, I have tried using OleDbCommand as well as OleDbDataAdapter... but none of it works. The database I am using in MS Access though.
Thank you in advance
|
|
|
|
|