|
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);
|
|
|
|
|
Try this:
MessageBox.Show((new UriBuilder("rs320tl.rapidshare.com")).Host);
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary;
using System.Collections;
namespace OrderForm
{
public partial class SubForm : Form
{
private TreeView s;
private ComboBox h;
Product c = new Product ();
private double[] prices = new double[100];
Store[] bee = new Store[100];
private string[] quantumItems = new string[4];
private double [] updatePrices = new double[3];
public SubForm()
{
InitializeComponent();
}
public SubForm(ComboBox h,TreeView s)
{
InitializeComponent();
h = new ComboBox();
s = new TreeView();
this.h = h;
this.s = s;
}
public ComboBox superSweet
{
get
{
return h;
}
set
{
h = value;
}
}
public TreeView superAwesome
{
get
{
return s;
}
set
{
s = value;
}
}
private void button2_Click(object sender, EventArgs e)
{
h.Items.Add(txtProduct.Text);
this.Close();
}
private void price_one_TextChanged(object sender, EventArgs e)
{
bee[1] = new Store();
string itemTwo = price_one.Text;
double ItemTwoConvert = Convert.ToDouble(itemTwo);
bee[1].superprice=ItemTwoConvert;
}
private void price_two_TextChanged(object sender, EventArgs e)
{
bee[2] = new Store();
string itemOne = price_two.Text;
double ItemOneConvert = Convert.ToDouble(itemOne);
bee[2].superprice = ItemOneConvert;
}
private void price_three_TextChanged(object sender, EventArgs e)
{
bee[3] = new Store();
string itemThree = price_three.Text;
double itemThreeConvert = Convert.ToDouble(itemThree);
bee[3].superprice = itemThreeConvert;
}
private void button1_Click(object sender, EventArgs e)
{
store_three.Visible = true;
price_three.Visible = true;
}
private void SubForm_Load(object sender, EventArgs e)
{
}
private void txtProduct_TextChanged(object sender, EventArgs e)
{
c = new Product();
c.supername = txtProduct.Text;
c.supercategory = cmbCat.SelectedText;
}
public void myAwesomeItem(string nice,string item,string item3, string item4,string item5, string item6)
{
txtProduct.Text = nice;
cmbCat.Text = item;
store_one.Text = item3;
store_two.Text = item4;
price_one.Text = item5;
price_two.Text = item6;
}
}
}
How would I keep what changes the user makes to the default values?
|
|
|
|
|
Wrap your code in a PRE blocks and specify the language. For example, if I type this into the message editor:
<pre lang="C#">public class MyClass
{
public void MyFunction()
{
MessageBox.Show("Hello");
}
}</pre>
It comes out looking like this:
public class MyClass
{
public void MyFunction()
{
MessageBox.Show("Hello");
}
}
|
|
|
|