|
Try this after applying the filter to the DataView:
<br />
foreach (DataRowView rowView in dvUK)<br />
{<br />
dtChildUK.Rows.Add(rowView.Row);<br />
}<br />
Fernando Mendes
Senior .NET Developer, Architect
|
|
|
|
|
|
Hello
You can use only this method of dv:
DataTable dtChildUK=dvUK.ToTable();
Simple and efficient.
Be Happy
Syed Shahid Hussain
|
|
|
|
|
Hey all,
I'm just trying to figure out why this bubble sort algorithm is ignoring the last element of the array.
namespace Bubble_sort
{
class SortArray
{
void BubblesortArray(int[] array)
{
int Position = 0;
int endpos = 0;
bool swapped = true;
while (swapped)
{
swapped = false;
Position = 0;
endpos = array.Length;
while (Position < endpos)
{
if (array[Position] > array[Position + 1])
{
int Temp = array[Position];
array[Position] = array[Position + 1];
array[Position + 1] = Temp;
swapped = true;
}
Position++;
endpos--;
}
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i].ToString() + ", ");
}
Console.WriteLine();
}
}
public static void Main(string[] args)
{
SortArray Sort = new SortArray();
int[] a = {1, 2, 3, 4, 1, 45, 134, 762, 2};
Sort.BubblesortArray(a);
for (int i = 0; i < a.Length; i++)
{
Console.Write(a[i].ToString() + ", ");
}
Console.Read();
}
}
}
thats the code (its a console app).
I do this out of curiosity, and annoyance( ) but i would like any help you could offer me.
Thankyou.
|
|
|
|
|
I'm hesitant to just give you the answer because this is a classic homework problem. Instead I'll give you some hints. (You'll feel better if you solve it yourself anyway)
Start by attaching a debugger and stepping through the code in the bubble sort routine line by line.
Each pass of a bubble sort should compare each adjacent pair of values. This routine doesn't. Look closely at the indexes you are using to the array being sorted. (Put watches on the values)
Simon
|
|
|
|
|
Thankyou for your help, simon. I suppose it does look like a homework problem my apologies for making it so. But the only reason I asked this is the site where I got it from has it written in a similar way i was just trying to figure out why the program didnt work.
Again my apologies.
|
|
|
|
|
No need to apologise. It's not your fault, it's a common question.
Did you manage to figure it out?
Simon
|
|
|
|
|
Yes I did thank you Simon. The step through debugger in VS took a little while to get used to but eventually it worked a treat. And i figured it out.
So, as always, logic prevailed over the human condition.
|
|
|
|
|
Hi,
i want to sepearte and count the string
s="aacbbcccddehgvfdd"
i need the Outputlike,
aa
bb
dd
dd
Count =4.
My question is : how will i get the out like the above
Please answer any one
|
|
|
|
|
What are you counting? Pairs of letters?
Just loop through the string, searching for pairs and keeping count.
Simon
|
|
|
|
|
Simon Stevens wrote: What are you counting? Pairs of letters?
All of them, yes!
|
|
|
|
|
leppie wrote: Simon Stevens wrote:
What are you counting? Pairs of letters?
All of them, yes! [Poke tongue]
But seemingly only explicit pairs (the 'ccc's are ignored).
In which case, loop through each character. For each character, if it matches the next one, but not the one after, then count it and move on. If you reach a repeated string of the same chars, jump over them all, and don't count them.
Simon
|
|
|
|
|
public static System.Collections.Generic.List<string>
FindSequences
(
string Chars
,
uint Length
)
{
System.Collections.Generic.List<string> result =
new System.Collections.Generic.List<string>() ;
char current = '\0' ;
int count = 0 ;
foreach ( char c in Chars )
{
if ( c != current )
{
if ( count == Length )
{
result.Add ( new string ( current , count ) ) ;
}
current = c ;
count = 0 ;
}
count++ ;
}
if ( count == Length )
{
result.Add ( new string ( current , count ) ) ;
}
return ( result ) ;
}
Though it'll fail when Length==0
|
|
|
|
|
Hi,
I'm new to C# and .Net architecture , so sorry about the silly question.... .
I'm using a grid control in order to display data from the data base.
My problem is when the user press the CTRL+C in a specific cell in order to copy the data
to a different cell.
The result is that the new cell contain the data of the entire row , instead of the data of the copied cell.
note that if I use the mouse right click and "copy" <-> "paste" it is working fine.
My question is how can I capture the CTRL+C and CTRL+V with the keyboard?
With best regards,
Eli
|
|
|
|
|
Are you talking about the DataGridView control? I don't seem to be having any sort of problem with CTRL-C, CTRL-V to copy and paste from cell to cell with that control.
Anyways, you might take a look at the grid's KeyDown event and see if you can use the e.Modifiers to capture the Control key, and e.KeyCode to capture the 'C' or 'V', but, to be honest, I don't think that event will trigger in an editable cell of the DataGridView. The other option I can think of is to override ProcessCmdKey and see if you can capture the key combinations there.
|
|
|
|
|
Some methods in the framework take the name of a method as a string, e.g. ObjectDataSource and most of WPF. I don't like this as the compiler and IDE tools can't link the string and the method. So I want to generate the string from the token. I came up with this:
class TestClass
{
public static void Test()
{
string s = GetName<string,int>( Method );
}
static int Method( string s ) { return 0; }
static string GetName<T,TResult>( Func<T,TResult> method )
{
return method.Method.Name;
}
...
GetName overloads for Actions and Funcs
...
}
This is ok, but I don't like having to specify the generic types when calling GetName .
I don't think there's a way around this, because method groups don't participate in type inferencing.
So my question is: is there a better way?
Thanks
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Although not exactly what you are looking for, but at least a bit more generic:
class TestClass
{
public static void Test()
{
string s = GetName( new Func<string,int>(Method));
}
static int Method(string s) { return 0; }
static string GetName(Delegate method)
{
return method.Method.Name;
}
}
I will try think of a better way
|
|
|
|
|
Thanks leppie, that is better.
You can also just use a cast:
string s = GetName( ( Func<string,int> ) Method );
But this doesn't work:
string s = GetName( ( Delegate ) Method );
----------------------------------
Be excellent to each other
|
|
|
|
|
Are you trying to get the method name from the method itself?
If so:
System.Reflection.MethodBase.GetCurrentMethod().Name
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Yes, but then he would have to call the method!
|
|
|
|
|
Hi there,
I am well aware of the usage of Control.Invoke() in a Form (System.Windows.Forms) to be able to access UI components in a thread-safe manner so that it is the thread that holds the window handle the one that executes it. I was wondering, if I don't have a reference to the Form but instead to the window thread (as a Thread object) is there a way to use that Thread object (or anything similar that can be extracted from the execution context) to do the same as Control.Invoke() ?
Background: I have a C# assembly (utils library) that calls into C++, but callbacks are returned in a separate thread, and I want the assembly to be application-independent but to return the callbacks (using events) in the same thread that the requests were made in.
Thanks in advance!
Carles
|
|
|
|
|
Say your thread calls MyCallbackObject.Callback().
Then you can test whether the object can synchronize the call and call it's Invoke() method if it does:
ISynchronizeInvoke synchronizeInvoke = MyCallbackObject As System.ComponentModel.ISynchronizeInvoke;
if (synchronizeInvoke == null)
{
MyCallbackObject.Callback()
}
else
{
synchronizeInvoke.Invoke(myDelegate);
}
where myDelegate is a delegate to a method wrapping MyCallbackObject.Callback().
|
|
|
|
|
Hello,
Useful classes are the System.ComponentModel AsyncOperationManager and AsyncOperation. I've pasted in some code that performs a directory search in a background thread. When complete the background thread raises on event on the thread that called BeginSearch.
This calling thread does not need to consider the source of the event and may use the information received in the EventArgs directly in any control.
Alan.
using System;
using System.ComponentModel;
using System.Threading;
using System.IO;
namespace SpecTest {
class DirectorySearchCP {
private AsyncOperation operation;
private String startDir;
private DirectoryInfo[] dirlist;
public event EventHandler<DirListEventArgs> SearchComplete;
public void BeginSearch(String startDir) {
this.startDir = startDir;
operation = AsyncOperationManager.CreateOperation(null);
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProcedure), null);
}
private void SearchDirectory() {
DirectoryInfo s = new DirectoryInfo(startDir);
dirlist = s.GetDirectories("*.*", SearchOption.TopDirectoryOnly);
}
private void ThreadProcedure(Object stateInfo) {
try {
SearchDirectory();
} finally {
operation.PostOperationCompleted(new SendOrPostCallback(OnSearchComplete), dirlist);
}
}
private void OnSearchComplete(Object state) {
EventHandler<DirListEventArgs> handler = SearchComplete;
if (handler != null) {
DirListEventArgs args = new DirListEventArgs();
args.dirlist = (DirectoryInfo[])state;
handler(this, args);
}
}
}
public class DirListEventArgs : System.EventArgs {
public DirectoryInfo[] dirlist;
}
}
|
|
|
|
|
Managed code .NET 3.5 C# WinForms application runs OK from Vista when in local drive.
When application is copied to mapped network drive or started from \\othercmp\c\myapp\myapp.exe folder , it does not start: Vista shows
MyApp has stopped working
Windows is checking for a solution to the problem..
How to fix ?
Andrus
|
|
|
|
|