|
Hello bugindia,
if I understand you hitting enter to move to the next cell in the same row, handle the KeyDown event of your datagrid class SystemKeys and force by moving the cursor to the right and subsequently has an example here.
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{Right}");
e.Handled = true;
}
}
Bye
|
|
|
|
|
What is better:
void AddSharpsAndFlats(StaffVisual staff, Clef clef)
{
int symbolCount = _context.GetSharpCount();
if (symbolCount > 0)
for (int i = 0; i < symbolCount; i++)
{
staff.AddVisual(new SharpVisual
{
Position = clef.SharpPostions[(int)MusicContext.SharpOrder[i]]
});
staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
}
else if (symbolCount < 0)
for (int i = 0; i < -symbolCount; i++)
{
staff.AddVisual(new FlatVisual
{
Position = clef.FlatPostions[(int)MusicContext.FlatOrder[i]]
});
staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
}
}
OR: move symbolCount < 0 inside a loop (and use abs(symbolCount))? Then I would have a single loop but I would also have n checks. Note: symbolCount is a value in range {-7,...,-1,0,1,...,7} .
EDIT: corrected typo
Thanks and
Greetings - Jacek
modified on Tuesday, July 5, 2011 7:50 AM
|
|
|
|
|
Your logic doesn't work here. You can't have i starting at zero and then being compared to symbolCount when symbolCount is less than zero. The loop won't run.
|
|
|
|
|
t'was a typo which came out while debugging a moment after I have posted this / forgot to correct. It's done now.
Greetings - Jacek
|
|
|
|
|
As these are mutually exclusive conditions, I think that having them as separate loops is a perfectly valid construct. As soon as you add the abs(symbolCount) condition in there, you are introducing something that requires thinking about by somebody reviewing your code. While this isn't, necessarily, a bad thing, consider that if this is a commercial project, then at some point, Nervous Nigel the spotty apprentice coder is going to try to do something with the code and end up breaking it because he doesn't understand it.
The KISS principal applies.
|
|
|
|
|
Nervous Nigel has just made its way into my weekly vocabulary. Describes people I often refer to perfectly. Thank you good sir.
|
|
|
|
|
You're welcome - I know several of them.
|
|
|
|
|
I dunno. Maybe squeeze the loops into a common method?
if (symbolCount > 0)
{
AddSymbols ( SharpFactory , clef.SharpPostions , staff , symbolCount ) ;
}
else if (symbolCount < 0)
{
AddSymbols ( FlatFactory , clef.FlatPostions , staff , symbolCount ) ;
}
Just a thought.
Otherwise, leave it the way it is.
|
|
|
|
|
The two loops set off my code style alarms. But having reviewed it, and worked out the domain here, it really is two separate operations, and there's not much there that is common enough to pull out. When it comes down to it you're duplicating four lines:
for(int i = 0; i < symbolCount; i++) {
staff.AddVisual(something);
staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
}
So I think I would leave it, but with a note (mental or explicit) to watch this space because if you add more key signature related stuff it could get messy and need refactoring.
Now you could take the duplication out like this:
void AddSharpsAndFlats(StaffVisual staff, Clef clef)
{
int symbolCount = _context.GetSharpCount();
if(symbolCount != 0){
var Positions = symbolCount > 0 ? clef.SharpPositions : clef.FlatPositions;
var Order = symbol.Count > 0 ? MusicContext.SharpOrder : MusicContext.FlatOrder;
VisualCreator creator = symbolCount > 0 ? (p => new SharpVisual(p)) : (p => new FlatVisual(p));
symbolCount = symbolCount > 0 ? symbolCount : -symbolCount;
for (int i = 0; i < symbolCount; i++)
{
staff.AddVisual(creator( {
Position = Positions[(int)Order[i]]
});
staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
}
}
}
... where
delegate VisualCreator(Position position);
(You could also have a VisualFactory that hides that selection away from you.)
I'm not convinced that for such a small duplication this is worthwhile.
|
|
|
|
|
Prompt to write a program to work with web camera to as I understand it to use OpenCV? Tell a escho library (preferably C #) to work with web camera and computer vision? and in what language it is better to write C # or C + + Open CV is a library of C + + swoop I know
|
|
|
|
|
Some good C# hits here[^].
The best things in life are not things.
|
|
|
|
|
Check out this article Motion Detection Algorithms[^]
It shows you how to integrate a webcam with motion detection.
It was the basis for this TeboCam[^]
One small tip - your question is very brief however computer vision is a hugely complex area - even Microsoft have a long way to go with the Kinect...
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Hi everyBody;
I want to browse my string like this:
int k = 0;
char car = ' ';
string successZero = string.Empty;
char[] arr;
arr = chaine.ToCharArray(0, chaine.Length);
if (arr [0] != '0')
{
while (k < chaine.Length)
{
car = arr [k];
if (car == '0')
{
successZero += car;
car = ' ';
k ++;
}
else
break;
}
}
else
successZero = "";
return successZero;
but if I enter "001" the arr [0]= 48 '0' and NOT '0' only
I don't know it appears to me that 48 (I know it is the ASCII of 0)
but I want to discutate sur arr[0] == '0' or not
How to remidiate to that?
ty
|
|
|
|
|
I'm not sure what you are trying to do but your code does not seem to correspond to your description. You are looking for a zero in the arry (maybe), or trying to count them, but the line:
if (arr [0] != '0')
means that you never enter the search loop if the first character of your string is '0', as is the case you describe.
The best things in life are not things.
|
|
|
|
|
Hi,
yes that what I search arr [0] appears to me always != '0' even I enter chaine = "001" it appears to me arr [0] = 48 '0'
what can I do?
ty
|
|
|
|
|
What are you expecting arr[0] to be?
With you input of "001" you can expect your array of characters to be:#
arr[0] = '0'
arr[1] = '0'
arr[2] = '1'
So in this case your code is going to me the condition of (arr[k] != '0') on the 3rd iteration of your loop, not on the first.
Is this what you’re looking for?
|
|
|
|
|
Pierre besquent wrote: yes that what I search arr [0] appears to me always != '0' even I enter chaine = "001"
No it doesn't; your coding logic is wrong as I stated in my previous answer.
I have a feeling something is still getting lost in translation here, but I cannot figure it out.
The best things in life are not things.
|
|
|
|
|
This is simply a viewing thing in your IDE. arr[0] will be '0' in this case. The problem is that if arr[0] is '0', the outer if fails, and if it is not '0', the if inside the while will fail on the first iteration and break out of the loop. You have a simple logic problem.
I think the outer if is entirely unnecessary (even if it is corrected).
|
|
|
|
|
Hi,
viewing thing in your IDE?what u mean. I debug and I found that arr[0] = 48 '0' even if chaine = "001". I know what i write so this it is my probleme: WHY it considerate arr [0] = 48 '0'??????
ty
|
|
|
|
|
Your debugger is showing to you that arr[0] contains char '0' which is the same as short 48.
short number = 48;
char letter = '0';
Console.WriteLine(number == letter);
Hope, this makes is clear.
|
|
|
|
|
Hi,
thanks for the clarification but still not clear HOW to test if arr [0] == '0' or not??
still my debugger returns to me arr [0] = 48 '0'.
ty
|
|
|
|
|
Pierre besquent wrote: HOW to test if arr [0] == '0' or not??
Well you could use a simple expression like:
if (arr[0] == '0')
if (arr[0] == 0x30)
if (arr[0] == 48)
You need to try and clarify your question as it is still not obvious to us what your problem is.
The best things in life are not things.
|
|
|
|
|
You are debugging in an IDE. It is showing you the integer value as well as the character, in case it is an unprintable character. arr[0] is still equal to '0' and the problem is that the two tests in your code contradict each other.
(edit: oops, not a BBcode forum.)
|
|
|
|
|
hi
how can I perform a group by on a DataTable's rows using dynamically determined group-by-columns?
For example, below, I group by "Symbol" and "Measure" - however, what if group by column is passed into the function as argument IList<string> GroupByColumnNames
<br />
static void TestLINQGroupBy()<br />
{<br />
#region Construct dummy data<br />
Random rnd;<br />
IList<string> Measures = new List<string>() { "eps", "bps", "close" };<br />
IList<string> Symbols = new List<string>() { "0001HK", "0002HK", "0003HK" };<br />
DataTable TestPrice = new DataTable("TestPrice");<br />
DataColumn c = null;<br />
DataRow newRw = null;<br />
<br />
DataColumn[] PKs = new DataColumn[3];<br />
c = new DataColumn("Symbol", typeof(string));<br />
TestPrice.Columns.Add(c);<br />
PKs[0] = c;<br />
<br />
c = new DataColumn("Measure", typeof(string));<br />
TestPrice.Columns.Add(c);<br />
PKs[1] = c;<br />
<br />
c = new DataColumn("RecordDate", typeof(DateTime));<br />
TestPrice.Columns.Add(c);<br />
PKs[2] = c;<br />
<br />
TestPrice.Columns.Add("Value", typeof(double));<br />
TestPrice.PrimaryKey = PKs;<br />
<br />
foreach (string Symbol in Symbols)<br />
{<br />
foreach (string Measure in Measures)<br />
{<br />
for (int iter = 1; iter < 12; iter++)<br />
{<br />
newRw = TestPrice.NewRow();<br />
newRw["Symbol"] = Symbol;<br />
newRw["Measure"] = Measure;<br />
rnd = new Random((Symbol + Measure + iter).GetHashCode());<br />
newRw["Value"] = rnd.NextDouble();<br />
newRw["RecordDate"] = new DateTime(DateTime.Now.Year, iter, 1);<br />
TestPrice.Rows.Add(newRw);<br />
}<br />
}<br />
}<br />
#endregion<br />
<br />
var q = from rw in TestPrice.Select()<br />
group rw by new {Key1=rw["Symbol"], Key2=rw["Measure"]} into key<br />
select key;<br />
foreach (var k in q)<br />
{<br />
Console.WriteLine(k);<br />
}<br />
return;<br />
}<br />
REF: 101 LINQ Examples[^]
dev
|
|
|
|
|
Have a look at this neat article[^], especially the GroupData function. Once you dynamically build the data, you can use
Func<DataRow, String> groupingFunction = GroupData; as shown in the article.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|