|
|
Hi,
I have a datagridview upon which I allow the user to re-order the columns. I then store the column order in a sqlServer database table. When the user starts the datagridview my code reads the database and retreives the user's column positions.
The code loops through the columns and sets the displayIndex as previously saved. No problems except the columns are displayed in the wrong order The effect is rather inconsistent and not all the columns are in the wrong order.
Under the debugger I can see the displayindices are correctly set as per the database table. The columns just appear in the wrong place on-screen
I have a fix I simply run the code that sets the displayIndices twice. The problem goes away (well up to now).
I wonder if anyone has had similar displayIndex problems and has a better fix? I have one or two comments in my code saying //DONT REMOVE THIS CODE. IT LOOKS WRONG BUT IS FIXING AN ISSUE.
Terry
|
|
|
|
|
Can you share the solution?
|
|
|
|
|
Hi,
I happend to have exactly the same strange problem! Unfortunately I have no better solution.
Has anyone else figured this one out or is it a DataGrid bug?
/Lars
|
|
|
|
|
Suppose your DataGridView has the columns A, B, C, but they should be displayed as B, A, C.
The desired column order will be restored from this table:
Column name Index DisplayIndex
A 0 1
B 1 0
C 2 2
Before you loop thru this table sort it by DisplayIndex:
Column name Index DisplayIndex
B 1 0
A 0 1
C 2 2
|
|
|
|
|
I'm trying to write a method to find out if a workbook is empty or not..
I'm using Excel 2007 and Microsoft.Office.Interop.Excel.Workbook.
If the workbook has content in more than one cell I'm able to detect this, but if I have an empty "workbookA" and a "workbookB" with content in cell A1 I'm not able to seperate these..
Does anyone have a hot tip? (It's hard to find anything on excel-automation on google..)
private bool IsWorkbookEmpty(Workbook excelBook)
{
try
{
if (excelBook.Sheets.Count <= 0)
{
return true;
}
else
{
foreach (Worksheet sheet in excelBook.Sheets)
{
Range excelRange = sheet.UsedRange;
int test1 = excelRange.Columns.Count;
int test2 = excelRange.Rows.Count;
int test3 = excelRange.Count;
if (test1 > 1 || test2 > 1 || test3 > 1)
{
return false;
}
else
{
foreach(Range cell in excelRange)
{
object test5 = cell.FormulaR1C1;
object test6 = cell.get_Value(Type.Missing);
}
}
}
}
}
catch (Exception)
{
return false;
}
return true;
}
|
|
|
|
|
Figured it out
private bool IsWorkbookEmpty(Workbook excelBook)
{
try
{
if (excelBook.Sheets.Count <= 0)
{
return true;
}
else
{
foreach (Worksheet sheet in excelBook.Sheets)
{
Range excelRange = sheet.UsedRange;
int test1 = excelRange.Columns.Count;
int test2 = excelRange.Rows.Count;
int test3 = excelRange.Count;
if (test1 > 1 || test2 > 1 || test3 > 1)
{
return false;
}
else
{
foreach(Range cell in excelRange)
{
if (cell.Value2 != null)
{
string cellValue = cell.Value2.ToString();
if (cellValue.Trim().Length > 0)
return false;
}
}
}
}
}
}
catch (Exception)
{
return false;
}
retur
|
|
|
|
|
WorkSheets = all your Worksheets
private void deleteUnUsedWorksheets()
{
foreach (Excel._Worksheet sheet in WorkSheets)
{
if (IsWorkbookEmpty(sheet))
sheet.Delete();
}
}
private bool IsWorkbookEmpty(Excel._Worksheet sheet)
{
ExcelRange = sheet.UsedRange;
if (ExcelRange.Columns.Count > 1 |
ExcelRange.Rows.Count > 1 |
ExcelRange.Count > 1)
return false;
else
return true;
}
You dont have to check each cell. Its senseless and you throw a lot of memory
Don`t throw a catch if its only a return false!
|
|
|
|
|
There are a some rectangular controls on a winform on which a dragdrop can happen.
When an item (which has a numeric value) is dragged over any of these controls, the control should show possible result by changing its shape (Increase area by numeric value).
This should be temporary. In case i move the item it out of the control without dropping, this change should revert back. Only in case the drop is done, the change should be permanent.
Now, this effect can be achieved using DragEnter and DragLeave. Currently, I am making the modification to the Control two times by adding the changes and removing the changes.
What I want to know now is whether it is possible to save the state of control so that it can be reverted back to the old state.
In reality, the changes are complicated than just adding area into the shape. But the concept remains same. Control needs to change temporarily and a simple method to restore its state needs to be achieved.
Is it possible?
|
|
|
|
|
Hi,
I would derive new Control types that do this, so make a ReshapableButton inheriting from Button, etc. And give them a boolean Reshaped property.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
OK. This is already there. Whenever there is a DragLeave event, the control checks if it was reshaped and then it draws itself once again after making changes back.
My question is how to save the details of control during DragEnter which can be easily resumed at DragLeave.
Serialization could be one solution. However implementing that within a class to handle itself, seems a bit tricky. Forms cannot be serialized easily.
So, basically I need a control that can save its state by serializing itself. When needed, it resumes from the serialized data. The fact that the control is on UI thread and it has to be a self managed code makes it tricky. I just need a clue how to implement this.
|
|
|
|
|
Hi,
I am looking for a " student tracking system" project using c#.net and sql server.
Let me know if there is any useful links.
Regards,
Savitha
|
|
|
|
|
savitha87k wrote: I am looking for a " student tracking system" project using c#.net and sql server.
Stop looking and start coding
savitha87k wrote:
Let me know if there is any useful links.
We are not here to find exsisting project. We are here to help for a specific code problem
Edit: typo
|
|
|
|
|
Hi,
I want to delete the duplicate and some hard coded XML node in XMLDocument throgh C#.
What is the method to do the same?
I am new to the use of XML in C#.
Please help me out.....!!!!!!!!!!!
Thanks
|
|
|
|
|
|
Hi,
There are some addresses as follows :
http:
I'm gonna select rs320tl.rapidshare.com with Regex , but I'm not familiar with Regular Expressions.
Would you please guide me ?
Thanks.
PS.
rs320tl in the address is variable.
|
|
|
|
|
^(ftp|http|file):
so
http :
1 2 3 4
so the reg expression would spit out
$1 = http
$2 = www.codeproject.com
$3 = /forum
$4 = /xxx.html
hope this helps.
|
|
|
|
|
Thanks,
How can I store $2 in a string?
|
|
|
|
|
string str = (new Regex("the pattern")).Match("the string").Groups[2].Value;
|
|
|
|
|
It doesn't work with www.codeproject.com
|
|
|
|
|
Try this instead of a Regex:
MessageBox.Show((new Uri("http://rs320tl.rapidshare.com/files/119371167/sth.rar")).Host);
|
|
|
|
|
I didn't know that a Uri broke it down for you - thanks for that! You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Under which namespace .host is come
|
|
|
|
|
I think you mean Uri. It's in the System namespace.
|
|
|
|
|
Thanks, but it throws an Exceptions on
MessageBox.Show((new Uri("rs320tl.rapidshare.com")).Host);
|
|
|
|