|
Member 2256533 wrote: int numberofrows = DG.Rows.Count;
int len = numberofrows.ToString().Length;
string NumberForRow;
for (x = 0; x < DG.Rows.Count; x++)
{
NumberForRow = Convert.ToString(x + 1);
while (NumberForRow.Length < len)
{
NumberForRow = "0" + NumberForRow;
}
DG.Rows[x].HeaderCell.Value = NumberForRow;
What length are you trying to get? this does not seem right. It looks you are trying to figure out how may digits are in a number. Is that right?
int len = numberofrows.ToString().Length;
int NumberForRow = 1;
foreach (DataGridViewRow row in DG.Rows)
{
if(NumberForRow < 10)
row.HeaderCell.Value = String.Format("{0:D2}", NumberForRow );
else
row.HeaderCell.Value = NumberForRow;
NumberForRow = NumberForRow+ 1;
}
|
|
|
|
|
True I am trying to find out how many digits are in the number so I can make the row headers all the same length. So if there are 1-9 rows the headers would look like 1,2,3,etc... and when there are 10-99 rows then 01,02...99, and 100-999 then 001,002,003...999 and this part works fine. The problem is that the row numbers don't show up at all in the first datagrid and they show up just fine in the second datagrid, using the exact same code.
|
|
|
|
|
For positive numbers this will do:
row.HeaderCell.Value = NumberForRow.ToString().PadLeft(requiredWidth, '0');
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
An update to the problem. I took the code above and made a separte function out of it. Then Added the call to it after the GF.LoadDataGrid call with the same result. No numbers. Then I added a button to the form that called the same function. After the page was rendered and I clicked said button and the numbers appeared. So it seems that for some reason after the numbers are put there and the grid is rendered the row numbers disappear. Not sure why?
|
|
|
|
|
Something like this won't do? (The DataGRidView has an unbound column added at column 0 for the index)
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
foreach (DataGridViewRow R in dataGridView1.Rows)
{
R.Cells[0].Value = R.Index;
}
}
EDIT: Oops. Never mind. Just noticed you want to put it in the row header cell....which doesn't work in the above code.
..and water fell from the sky like rain.
|
|
|
|
|
Daniel Soper appears to have a nice solution which he describes here
"You get that on the big jobs."
|
|
|
|
|
Hey ,
I have this task but I don't know what I should do , Please help me.
task :
-------------
An integer that is greater than zero is said to be n-factored if it has n distinct factors other than 1 and itself. For example 12 is 4-factored because its factors are 2, 3, 4, 6. A prime number is 0-factored.
Write a function named isNFactored that takes two arguments, an integer and some value of n, and returns 1 if the integer is n-factored. The function signature is
int isNFactored(int value, int n)
|
|
|
|
|
if value n return reason
14 2 1 14 has two factors, 2 and 7
18 5 0 18 does not have 5 factors, it only has four (2, 3, 6 and 9)
25 2 0 25 = 5*5 but we are only interested in distinct factors so the 5 is only counted once.
36 7 1 36 has seven factors (2, 3, 4, 6, 9, 12, 18). Note that 6 is counted only once.
7 0 1 all prime numbers are 0-factored
-5 anything 0 the value must be greated than 0
and I do code know but I doesn't know what is meant by return type?
public static int GetFactorCount(int numberToCheck, int n)
{
int factorCount = 0;
int sqrt = n;
for (int i = 1; i < sqrt; i++)
{
if (numberToCheck % i == 0)
{
factorCount += 2;
}
}
if (sqrt * sqrt == numberToCheck)
{
factorCount++;
}
return factorCount;
}
|
|
|
|
|
It is really easy to count the number of prime factors of a number. I will not give you the implementation, but can help you with the algorithm.
1. Define a factorCount variable and initialize it to 0.
2. Define a factor variable and initialize it to 2.
3. If factor is equal or bigger than the number to check, goto step 6, else, continue by step 4.
4. If factor divides the number to check:
4.1 Increase factorCount by 1.
4.2 Divide the number to check by factor.
4.3 Go to step 4.
5. Increase factor by 1.
5. Go to step 3.
6. Return factorCount.
That is all.
modified on Tuesday, February 8, 2011 9:44 AM
|
|
|
|
|
You probably need to start by researching any algorithms that solve the mathematics of this question. Once you know that solution it should be a simple matter to convert it into the programming language of your choice.
Is this really a .NET question?
I must get a clever new signature for 2011.
|
|
|
|
|
Richard MacCutchan wrote: Is this really a .NET question?
Technically, no...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Try something and post the code here (if you face any issues).
Someone will try and help you.
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.
My latest tip/trick
|
|
|
|
|
Since the function signature is quite misleading from a C# point of view, let me give you some hints:
the return value is actually a boolean: "returns 1 if the integer is n-factored", and implicitly 0 otherwise - that's a stone-age coding praxis typical of C or COM. Now you can start to interpret the parameters: "value" should be the integer number for which to find the number of factors, and "n" the number of factors. I.e. if "value" has "n" factors return 1, otherwise 0.
Now take the code you've posted, and make little changes: calculate "sqrt", then compare "factorcount" and "n" for getting the return value.
|
|
|
|
|
I have a CustomerInfo form which is an Mdi form to the main form. The CustomerInfo form a has TabControl with 4 TabPages on it.
From the Main form
CustomerInfo CI = new CustomerInfo();
In the form constructor event i have the following pseudeocode
LoadGeneralTab()
LoadOrderTab()
LoadInvoiceTab()
LoadPayHistoryTab()
Each of these functions loads several Datagrids with information.
Then from the main form
CI.MdiParent = this;
CI.Show();
The CustomerInfo form shows up as expected and all is good. But when I click on the orderTab or invoiceTab or the payHistoryTab it takes a long time to switch over to it. And the speed of the switch seems to be the amount of information contained in the datagrid views. What I don't understand is why this is happening as it seems to me that all the grids have been populated with information in the constructor so what is taking so long to switch over. I have done this before and not had the same problem. And help would be appreciated.
|
|
|
|
|
Member 2256533 wrote: And the speed of the switch seems to be the amount of information contained in the datagrid views
Doesn't that answer your question. That implies you need to look closer to how the data is retrieved. May be you need to optimize your query. It is kinda hard to tell without looking at the code.
|
|
|
|
|
No not really, It does take some time for the CustomerInfo form to show up, and I assume that is because it does take time to load all the information on each of the tabs. But once the CustomerInfo form is displayed all the information should be loaded. So switching between tab pages should be quick. But it seems that the tabs are being reloaded everytime I switch over to them.
|
|
|
|
|
I guess the Controls (DGVs) that haven't been visible yet (those not on the first tab page) still haven't been rendered at all; so clicking on a tab will first cause the DGV to be actually created (including its Handle property), then the data being loaded into it.
You could force this to happen sooner, IIRC reading Control.Handle suffices to make sure it really exists. Of course adding this to your Form.Load (or Shown) event will postpone its rendering of everything, including the first tab.
A better way to handle the situation could be this, and I would recommend it anyway whenever the database accesses might take more than a second:
- launch a thread to access the database, do not touch the Controls from that thread;
- in the mean time, make sure all Controls really exist (Handle!);
- when the database thread is done, make it signal the GUI thread and start showing the data.
A BackgroundWorker would be good, having the DB stuff in its DoWork and the show-in-GUI stuff in its RunWorkercompleted handler.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
It's the grids doing it, not the database access as such.
If you can "page" the results for the grids, only loading as many rows as will be displayed, it should speed up a bit.
..and water fell from the sky like rain.
|
|
|
|
|
I'm writing a program that uses net framework 4. another person will use this program in his own computer. Is it necessary for he/she to have net framework 4 installed in his/her computer? which version he/she will require?
Thanks,
Sia swar
Baluch
|
|
|
|
|
If you build it to run on .Net 4, the target machine will need to have .Net 4 installed.
Will Rogers never met me.
|
|
|
|
|
They will need .NET installed on there machine. Framework 4.0 will be required. It must also be a Windows operating system and in fact if it is Windows 7, it should have it already installed.
Best to create a installation for your app that will handle the dependency for .NET. Test the installation before releasing.
It shouldn't be a big deal.
"You get that on the big jobs."
|
|
|
|
|
FYI: some 8 months ago my then new Win7 laptop had all .NET versions installed up to 3.5, I had to install 4.0 myself.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I forgot it was just a recommended update for Windows 7 and Vista. So in most cases .NET 4 will be installed on Windows 7 but not all.
"You get that on the big jobs."
|
|
|
|
|
Yes they will require Framework 4.
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.
My latest tip/trick
|
|
|
|
|
I went for a job interview a while ago and failed on this question. I have researched it but can not find a definitive answer. Can someone point me to definitive documentation which clearly explains disposing of objects which have subscribed or registered events.
If the GC attempts to collect ClassA and finds it subscribes to an event of ClassB. Will ClassA be removed from memory?
If the GC attempts to collect ClassB and finds ClassA subscribes to an event of ClassB. Will ClassB be removed from memory?
I was not aware of this issue but the person interviewing me seemed concerned. At the end of the day, I don't care, I'd just like to find out what the truth is regarding eventing and disposing of objects.
"You get that on the big jobs."
|
|
|
|