|
Hi there, I want to know how to insert a row into excel I created a file and in my form I am loading that file and putting values into it but when I load my dataset into it, it goes over some records. I just want to know how to insert a row. Thank you
|
|
|
|
|
How are you writing data to your spreadsheet?
Paul
|
|
|
|
|
sorry what do you mean?I am using the microsoft directive
using System;
using Microsoft......
|
|
|
|
|
You want to insert a row into an Excel spreadsheet. Could you post your code and be more specific about what the problem is?
Also, please don't post the same question twice in the forum. It is considered rude and won't help you get your question answered any quicker.
Paul
|
|
|
|
|
If you're referring to using Microsoft.Office.Interop.Excel; then you can give this a try:
Range cell1 = (Range)worksheet.Cells[rowNumber, 1];
int lastUsedCol = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Column;
Range cell2 = (Range)worksheet.Cells[rowNumber, lastUsedCol];
Range entireRow = worksheet.get_Range(cell1, cell2);
entireRow.Insert(XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
|
|
|
|
|
Hi,
I have some RichText control and i want to cancel the option of 'Select' ( i mean i want to cancel any option of selection text by the user ).
How do i do it ?
Thanks.
|
|
|
|
|
I believe you can achieve it by manipulating SelectedText, SelectionStart and SelectionLength properties of richtextbox control. You might not need all three properties.
|
|
|
|
|
RichTextBox.SelectionStart = RichTextBox.Text.Length;
RichTextBox.SelectionLength = 0;
Pawel
|
|
|
|
|
This is good solution - but it also disable my richText color that i change of some of the string in my text.
|
|
|
|
|
i think that i misunderstood your question.
do you want to not allow user to use his mouse to select some of the text in rich text box by his own? for example by mouse?
if so, i'd do that like this:
hold information about last selection made by you and a bool which states if you want to select something new now.
RichTextBox has an event: SelectionChanged. In this event if your bool is true do nothing, if the bool is false use code given by me in previous asnwer.
if it doesn't resolve your problem try to state it more accurately.
|
|
|
|
|
Hi,
I have a form that does a lot of processing, some using background threads.
What I want to do is "disable" any user actions until the processing is finished BUT still have the prgressbar continue if the user does try to click on the form somewhere.
I have tried the lock method but this freezes the progressbar if a user clicks somewhere. I've also tried disabling the main form but that doesn't disable individual controls on that form, especially tab pages.
I don't want to completly rewrite my program using all background threads.
How can I disable any user interaction?
TIA for any suggestions.
Glen Harvy
|
|
|
|
|
this.UseWaitCursor=true; can help you
|
|
|
|
|
Unfortuately that doesn't stop the user from clicking on a control on the form causing the status bar to freeze.
Glen Harvy
|
|
|
|
|
The normal way to solve this would be to open a modal dialog that holds the progress bar
and a Cancel Button.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
When opening the modal dialog how do I allow the mainForm to continue processing?
I have always thought that the normal way of doing it was to create a backgroundworker, have it do the processing and update a progress bar on the main form.
Glen Harvy
|
|
|
|
|
Hi Glen,
Disabling a form can be handled in several ways: you can disable all the Controls
(not recommended), hide the form, or make sure it can't get focus (that is exactly what
you get with a modal dialog).
There are many ways to get the work done; using a Thread, a ThreadPool thread, or a
BackgroundWorker are amongst them. And that is independent of your form situation;
the thread or whatever simply runs in the background; it gets organized by either the
form or the modal dialog, your choice.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi,
I have made a custom class to populate a TreeView thru its ItemsSource. That class heritates ObservableCollection.
The thing is that its nodes doesnt seem to be TreeViewItems because i cant apply code that works for normal treeviewitems.
I'm talking about code to do right click select, etc.
What i really want is to be able to automaticly select a node when i right click it, and then open the context menu.
I can do this perfectly using the left button to select the node and then using the right click to access the context menu.
The problem is that i cant use directly the right button which is something typical in windows enviorment.
The code i'm using to achieve that is the following:
Code Snippet
tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown));
private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e)
{
TreeViewItem item = e.Source as TreeViewItem;
if (e.RightButton == MouseButtonState.Pressed)
{
item.IsSelected = true;
}
}
I think this happens because the items are not tree view items, as stated before, they are items from an observable collection of a custom type.
How can i make such behaviour to happen?
The problem is that even using the visual tree help i always get the first node.
I need to show you the big picture. Maybe i have something really small failing:
XAML:
<treeview width="Auto" height="Auto" dockpanel.dock="Top" cliptobounds="False" snapstodevicepixels="False" borderbrush="{x:Null}" fontweight="Normal" x:name="tvNetworkExplorer" background="{x:Null}" margin="5,5,5,5">
<treeview.resources>
<hierarchicaldatatemplate datatype="{x:Type src:Group}" itemssource="{Binding Path=Items}">
<textblock text="{Binding Path=Name}">
<hierarchicaldatatemplate datatype="{x:Type src:GroupItem}" itemssource="{Binding Path=List}">
<textblock text="{Binding Path=Title}">
<datatemplate datatype="{x:Type srcStick out tonguelayer}">
<textblock text="{Binding Path=Name}">
<datatemplate datatype="{x:Type src:Behaviour}">
<textblock text="{Binding Path=Name}">
<treeviewitem itemssource="{Binding}" header="Network">
Code:
tvNetworkExplorer.DataContext = networkExplorer;
// Events
tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown));
tvNetworkExplorer.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(TvNetworkExplorer_SelectedItemChanged);
private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e)
{
//TreeViewItem item = e.Source as TreeViewItem;
TreeView tv = (TreeView) sender;
TreeViewItem obj = (TreeViewItem) GetBoundItemFromPoint(tv, e.GetPosition(tv));
Console.WriteLine(obj.Name);
//Console.WriteLine(item.ToString());
//if (e.RightButton == MouseButtonState.Pressed)
//{
// item.IsSelected = true;
//}
}
static private object GetBoundItemFromPoint(TreeView tv, Point point)
{
UIElement element = tv.InputHitTest(point) as UIElement;
while (element != null)
{
if (element == tv)
return null;
object item = tv.ItemContainerGenerator.ItemFromContainer(element);
bool itemFound = !object.ReferenceEquals(item, DependencyProperty.UnsetValue);
if (itemFound)
return item;
else
element = VisualTreeHelper.GetParent(element) as UIElement;
}
return null;
}
The result of the right click is always the first treeviewitem, the one that has "Network" as header in the XAML.
But this is a contradiction as i can select the nodes in the tree with the left click.
Help here, please...
Best regards,
Nuno
|
|
|
|
|
I'm facing the same problem. I somehow managed to get it selected in the similar way and opened the contextmenu like
TreeViewItem.ContextMenu.IsOpen=true;
but the problem that occurred was, the commands bindings to the menu items(in xaml) don't work.
|
|
|
|
|
hi,
I want to serialize a class which has the two kinds of elements. Custom elements (non graphic and made by me, which are serializable by the XmlSerializer), and UI Elements from the WPF. The class which i want to serialize is this:
Code Snippet
public class Region : ISerializable
{
private Control _control;
public Control Control
{
get { return _control; }
set { _control = value; }
}
private Border _bounds;
public Border Bounds
{
get { return _bounds; }
set { _bounds = value; }
}
public Region()
{
}
///
/// Initializes a new instance of the class.
///
public Region(Border bounds)
{
_bounds = bounds;
}
public Region(SerializationInfo info, StreamingContext ctxt)
{
this._control = (Control)info.GetValue("Control", typeof(Control));
this._bounds = (Border)XamlReader.Load(new XmlTextReader(new StringReader((string)info.GetValue("Bounds", typeof(string)))));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("Control", this._control);
info.AddValue("Bounds", XamlWriter.Save(_bounds));
}
}
As you can see, this class is composed by a Control (custom made class specified by me) and a Border (UI Element). The class was serializable if i didnt have the border on it.
My attempt was to override the Iserialize methods in order to have serialization of the border based on XamlWriter.Save but it gives me error before getting there, in the following line:
Code Snippet
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Region));
With the message:
Code Snippet
"There was an error reflecting property 'Bounds'."
How can i solve this problem?
Thx,
Nuno
|
|
|
|
|
Dictionary<string, listviewitem=""> list = new Dictionary<string, listviewitem="">();
String nameAndJob, Job, line, name;
Int32 pages;
ListViewItem item1;
foreach (ListViewItem lvi in listView2.Items)
{
nameAndJob = string.Concat(lvi.SubItems[0].Text);
if (!list.ContainsKey(nameAndJob)) list.Add(nameAndJob, lvi);
Job = string.Concat(lvi.SubItems[1].Text);
if (!list.ContainsKey(Job)) list.Add(Job, lvi);
}
using (StreamReader sr = new StreamReader(path1 + "/personalpr.txt"))
{
while (sr.Peek() > 0)
{
line = sr.ReadLine();
if (line == "#")
{
name = sr.ReadLine();
nameAndJob = string.Concat(name);
Job = string.Concat(name);
if (list.ContainsKey(nameAndJob))
{
item1 = list[nameAndJob];
item1 = list[Job];
item1.SubItems[1].Text = sr.ReadLine();
item1.SubItems[3].Text = sr.ReadLine();
item1.SubItems[5].Text = sr.ReadLine();
}
int result = 0;
foreach (ListViewItem lvi in listView2.Items)
{
result += int.Parse(lvi.SubItems[2].ToString()) - int.Parse(lvi.SubItems[3].ToString()); ????????????????????
////I want to calculate lvi.subitems[2] - lvi.subitems[3] and pass the result to subitems[3].
}
item1.SubItems[3] = result.ToString();???????
}
}
}
}
Can i delete this readline from .txt file after this use??? and how??
Thanks all!! ;)
|
|
|
|
|
As you are reading the input file, you should generate a corresponding output file. Copy only the data you want to keep from the input file to the output file. When you have finished reading the input file, overwrite it with the output file.
aul
|
|
|
|
|
Any idea how to encode Arabic letters after retrieving them from a database?? I'm using Oracle8i and I made sure they're stored correctly and can view them correctly from sql*plus but not from a windows form.
Please help
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hello Muammar,
Have you set a correct Unicode Font to the Control which should show the text?
All the best,
Martin
|
|
|
|
|
Thanks Martin , I should try that
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi Everyone,
I want to create something similar to www.20q.net but for business application. I know it uses a neural net (for which I have already created a library). But a neural net alone is not enough.
Can someone point out to me how I could design this 20 questions app and what algorithm/data structures I should use?
Any help would be appreciated!
Regards,
Andre
|
|
|
|