|
OR
<br />
DataView view = new DataView( dsSource.Tables[0], "col1 = " + ... Value ..., "", DataViewRowState.CurrentRows );<br />
Good Luck
Alex Kucherenko
|
|
|
|
|
Lets say I have a Dataset which contains one table, multiple datarows, and multiple populated datacolumns.
I want to add another column to this dataset BUT I need to add it at a specific postion. For example there are 20 datacolumns and I want to insert a column at position 7 (shuffling all the others up)
I have been looking at Columns.Add() but I cant find any functionality to allow me to specify postion as this seems to just add the new column to the end of the datarow.
Does anybody know of a way of doing this, without disassembling the dataset and rebuilding with the new column.
|
|
|
|
|
<br />
DataSet dsSet;<br />
DataTable table;<br />
<br />
<br />
DataColumn[] columns = new DataColumn[ table.Columns.Count ];<br />
table.Columns.CopyTo( columns, 0 );<br />
<br />
table.Columns.Clear(); <br />
<br />
ArrayList lst = new ArrayList( columns );<br />
<br />
lst.Insert( ... );<br />
lst.RemoveAt( ... );<br />
lst.Add( ... );<br />
<br />
table.Columns.AddRange( ( DataColumn[] )lst.ToArray( typeof( DataColumn ) ) );<br />
<br />
lst.Clear();<br />
Only one note... I don't know what will happens with DataTable Data...
Good Luck
Alex Kucherenko
|
|
|
|
|
That works brilliantly but as you mentioned there is a problem with the data, it isnt carried across into the dataset.
The code I am using at the moment is this :
<br />
DataColumn[] columns = new DataColumn[ dsSource.Tables[0].Columns.Count ];<br />
dsSource.Tables[0].Columns.CopyTo( columns, 0 );<br />
ArrayList lst = new ArrayList( columns );<br />
dsSource.Tables[0].Columns.Clear();<br />
<br />
DataColumn dc = new DataColumn();<br />
lst.Insert(7, dc);<br />
<br />
dsSource.Tables[0].Columns.AddRange( ( DataColumn[] )lst.ToArray( typeof( DataColumn ) ) );<br />
<br />
lst.Clear();<br />
Currently working on getting the data across
|
|
|
|
|
Try such way:
- create copy of DataColumns
- change in copy name to unique one (add prefix to names)
- add copy DataColumns to collection
- ??? map data of old columns to new columns ??? (how to do that???)
- remove old columns from collection
- change names of columns to default one (remove prefix from names)
I don't know how to re-map columns data, but i think this is easier to do then copy all data from dataset...
Good Luck
Alex Kucherenko
|
|
|
|
|
I am currently working on a variation of the code you posted earlier.
Rather than working with columns I am working with the datarows as these seem to maintain the data within them
this is the code I have at the moment
<br />
DataRow[] rows = new DataRow[ dsSource.Tables[0].Rows.Count ];<br />
dsSource.Tables[0].Rows.CopyTo(rows, 0);<br />
ArrayList lst = new ArrayList( rows);<br />
DataSet dsNew = new DataSet();<br />
<br />
foreach(DataRow drs in lst)<br />
{<br />
ArrayList lst2 = new ArrayList(drs.ItemArray);<br />
lst2.Insert(3, "Insert Value");<br />
DataRow ndr = dsNew.Tables[0].NewRow();<br />
<br />
<br />
dsNew.Tables[0].Rows.Add(ndr);<br />
}
My only problem is getting the arraylist of row values back into the new datarow, but I have only been stuck here for a few minutes, hopefully the solution will come to me soon
|
|
|
|
|
Well here it is, this piece of code will take a dataset (dsSource) add a column and write the results into a second dataset (dsNew).
Its dirty, it aint pretty, but it does the job (ish)
<br />
DataRow[] rows = new DataRow[ dsSource.Tables[0].Rows.Count ];<br />
dsSource.Tables[0].Rows.CopyTo(rows, 0);<br />
ArrayList lst = new ArrayList( rows);<br />
DataSet dsNew = new DataSet();<br />
dsNew.Tables.Add();<br />
<br />
for (int i=0; i<dsSource.Tables[0].Rows[0].ItemArray.Length + 1; i++)<br />
dsNew.Tables[0].Columns.Add();<br />
<br />
foreach(DataRow drs in lst)<br />
{<br />
ArrayList lst2 = new ArrayList(drs.ItemArray);<br />
lst2.Insert(3, "INSERT VALUE");
DataRow ndr = dsNew.Tables[0].NewRow();<br />
ndr.ItemArray = lst2.ToArray(); <br />
dsNew.Tables[0].Rows.Add(ndr);<br />
}<br />
EDIT : hmm, the code tags seem to have messed up that for loop it should be :
for (int i=0; i
|
|
|
|
|
how do i get windows to notify me of multiple events? eg a mouse click and a mouse over another contorl at the same time?
i have a button and a panel, when i click and hold the mouse button down over the button an event is fired, if i keep the mouse button clicked and move over the panel the mouseover event for the panel is not fired, it is fired only when i relase the mouse button
is there a way of getting round this problem? i need to know the mouse over events occuring.
thanks
|
|
|
|
|
How can I trap an event when a column of listview control is resized in C#?
|
|
|
|
|
Hi.
I'm having problems with code that worked until just recently. I have a C# komponent which uses SmtpMail to send an e-mail, but now I get an exception. With stack trace it looks like follows:
[SEHException (0x80004005): External component has thrown an exception.]
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly) +0
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +64
System.Web.Mail.SmtpMail.Send(MailMessage message) +150
The component still works on my normal computer (where I run XP) and the only thing I can remember doing on the mashine acting as server (running Win2000) is that I uninstalled IE 6, because I wanted to see a webpage in IE 5.5. It didn't feel like it should matter but now the component does not work. I have reinstalled IE 6 and updated with all the latest patches and so on, but it still wont work. Can there be some setting that may have changed and now is preventing an instance from some component to be created?
Code sample:
MailMessage vscMail=new MailMessage();
vscMail.To="myemail@hotmail.com";
vscMail.From="myemail@hotmail.com";
vscMail.Subject="Sending an e-mail";
vscMail.Body="Hello world!";
SmtpMail.SmtpServer=strSmtpServer;
SmtpMail.Send(vscMail);
Any idéas or hints?
Thanks
/EnkelIk
|
|
|
|
|
Version 1.0.3705 on both. On the one where it works I have complete Visual Studio .Net installed, on the one it doesn't work I just have the framework.
|
|
|
|
|
I tried installing Framework 1.1, but unfortunatelly it didn't help.
|
|
|
|
|
So far .net 1.1 seems neither to have helped nor harmed -it still doesn't work.
I got the idea that the trouble could be in the connection to the smtp-server so I tried setting the SmtpMail.Server to "localhost" (and also not to set it at all) but the exception was the same, even when I stopped the Default SMTP virtual server running on the "win2000-machine". My conclusion is that the exception occurs before the application even tries to connect to the smtp-server.
Do you think uninstalling .net frameworks all together and then reinstalling it might help?
Thanks
/EnkelIk
|
|
|
|
|
Ok. That sounds like a good idea but there are two problems: 1. I do not have Visual Studio on the mashine 'causing trouble', and if I run the program, "physically" on that mashine, in debugger in Visual Studio on my other mashine everything goes fine -the exception is not thrown.
2. To find out what was going wrong I would have to debug into the SmtpMail.Send function and I have not found a way to do that.
The reason why I hoped uninstalling and reinstalling .net framework would make a difference is the fact that the SmtpMail.Send worked on both mashines earlier...
Thanks
/EnkelIk
|
|
|
|
|
I need to monitor if there're any change to some files after some interval of time. To do this, i have to somehow know when the file is last modified. We can do it easily by right-clicking on the file and click on its property. But, in terms of coding, i need to know how to read the property/ where to find information about a file's property.
Anybody knows? please help me out
thanks
puppiesLover
|
|
|
|
|
Do you need to be notified when it's modified, or do you just want to store the modified time at one point and compare it again later?
If you just want to store and compare then does the System.IO.FileInfo class do what you'd like?
<br />
using System;<br />
using System.IO;<br />
<br />
FileInfo info = new FileInfo( "myfilename" );<br />
DateTime modified = info.LastWriteTime;<br />
n!
|
|
|
|
|
Hi! I'm developing an application that hosts a WebBrowser control. Users will be able to input information into the pages but the information must be transferred to the application. The thing is that the pages content and controls are unknown and will change from time to time. My approach was to have some javascript code into the pages to handle the validation in each page and then "transfer" the information to the win form.
My question is how to call the javascript functions in the html pages. After searching the .NET documentation I found the execScript() function in the IHTMLWindow2 interface. I managed to get the IHTMLWindow2 reference through the WebBrowser.Document.parentWindow object (with the necessary casting to IHTMLDocument2).
The execScript() function worked and executed the defined functions in the HTML pages but the problem is that there is no way to get the return value of the functions.
After searching the MS site I found an article titled
"HOWTO: Call a Script Function from a VC WebBrowser Application (Q185127)" [http://support.microsoft.com/default.aspx?scid=kb;en-us;185127]
that handles a similar situation but using C++ code.
I need to know how to execute a javascript function from an HTML file in a WebBrowser control and then retrieve the return value of the functions, using a C# application. Here is included the VC++ code from the article. Since my COM experience is poor and my C++ experience is very limited (old DOS-Turbo C++), any help in porting the C++ code to C# managed code is extremely appreciated. All corrections, ideas and workarounds are welcomed and appreciated.
Thanks, Alberto Colon .
Here goes the article code (c++):
<br />
#import "C:\winnt\system32\mshtml.tlb"
<br />
void CMyClass::ExecuteScriptFunction()<br />
{<br />
MSHTML::IHTMLDocument2Ptr spDoc(m_WebBrowser.GetDocument());<br />
<br />
if (spDoc)<br />
{<br />
IDispatchPtr spDisp(spDoc->GetScript());<br />
if (spDisp)<br />
{<br />
OLECHAR FAR* szMember = L"evaluate";<br />
DISPID dispid;<br />
<br />
HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,<br />
LOCALE_SYSTEM_DEFAULT, &dispid);<br />
<br />
if (SUCCEEDED(hr))<br />
{<br />
COleVariant vtResult;<br />
static BYTE parms[] = VTS_BSTR;<br />
<br />
COleDispatchDriver dispDriver(spDisp, FALSE);<br />
<br />
dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,<br />
(void*)&vtResult, parms, "5+Math.sin(9)");<br />
}<br />
}<br />
}<br />
}<br />
The following is the HTML for the Web page that contains the evaluate function:
<br />
<SCRIPT><br />
function evaluate(x)<br />
{<br />
alert("hello")<br />
return eval(x)<br />
}<br />
</SCRIPT><br />
|
|
|
|
|
Is there a way to change the icon that is displayed in the task bar (not systray) at runtime?
|
|
|
|
|
I am looking to reproduce the behavior of PostMessage(), but I would like to avoid using the Win API if I could.
I have read and worked with the delegates and events. This works well in a SendMessage() type process. But I really want the subscriber to wait until the thread hits the OnIdle() process. To sum up I am looking for a .Net way to perform PostMessage().
Can you point me towards an example or further reading? :-OThanks.
|
|
|
|
|
Look into BeginInvoke... this method works like PostMessage...
In my application I use PostMessage API...
Good Luck
Alex Kucherenko
|
|
|
|
|
here's how to postmessage :
VB:
[DllImport("User32.Dll")]
<font color="blue">Public</font> <font color="blue">Static</font> extern int PostMessage (int hwnd,int wMsg,int wParam,int lParam);
<font color="blue">Public</font> <font color="blue">Const</font> int WM_CLOSE = 0x10;
<font color="darkgreen">'//// where you'd normally put your declares ^^^</font>
<font color="darkgreen">'////</font>
<font color="blue">Private</font> void button1_Click(<font color="blue">Object</font> sender, System.EventArgs e)
{
<font color="blue">Try</font>
{
PostMessage(this.Handle.ToInt32(),WM_CLOSE,0,0);
}
<font color="blue">Catch</font>
{
System.Exception r=new System.Exception();
MessageBox.Show(r.Message.ToString());
}
}
hope that helps a bit .
My Signature Below
<font color="blue">Private void</font> ExpectingTwins(<font color="blue">string</font> twins)
{
<font color="blue">switch</font>(twins)
{
<font color="blue">Case</font> ("twins on the way"):
MessageBox.Show("for mr and mrs dynamic","twins on the way");
<font color="blue">break</font>;
}
}
|
|
|
|
|
|
Hi
I just downloaded the .NET Framework SDK 1.1 and SharpDevelop to take my first steps with C#. For now, I,ve been programming only with C++ so far. I like C# due to its consequent OOP-design, and many other things (such like the garbage collection). But after a few minutes I got the first shock:
I wanted to use some native Win32 API calls like FindWindow, SendMessage and so on. But....I had to declare all these functions by myself and convert them to C#-syntax
That's the thing I hate most e.g. in VB, where you have to do the crap as well.
So my question is: Why is that the case? How are the chances that one time it will be possible to call the Win32 APIs without the need to declare them first?
thanks in advance,
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Excuse my ignorance - but isn't that what wihdows.h does for any vc++ program? i.e. define them and even sometimes modify their syntax?
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Greg S. wrote:
I wanted to use some native Win32 API calls like FindWindow, SendMessage and so on. But....I had to declare all these functions by myself and convert them to C#-syntax
That's the thing I hate most e.g. in VB, where you have to do the crap as well.
So my question is: Why is that the case? How are the chances that one time it will be possible to call the Win32 APIs without the need to declare them first?
Only when they've all been declared (sort of like win32api.txt). I tried to get people interested in doing this once as an open-source project sot of a thing, but nobody was interested. Meanwhile, I've been declaring every single API I use, knowing that others are doing the same, and wishing that we could all collaborate and write up about 3000 or so of the most common ones and put them in a library.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|