How to create a new extension to save an Excel file? Similar to .xlsx is it possible to create new extension using C# eg: .newext
Is it possible to make a new Excel extension like .xlsx? While saving the file, a new extension should appear in the help list.
1 answer
-
answered 2021-04-08 03:43
Ethan
For example, in the WinForm project
var dialog = new SaveFileDialog(); dialog.AddExtension = true; dialog.Filter = "The custom(*.newext)|*.*"; dialog.ShowDialog();
See also questions close to this topic
-
SqlDataReader can only check for one of (Null or non null value)
I am writing a program (for personal use) that stores card names into a database. I want to implement a way to see if a name already exists and if it does it will go in a "Do_have_in_db_listbox" else it will go in a "do_not_have_list_box". This is my original method for doing so:
while (retrieve.Read()) { if(retrieve["Card"] != DBNull.Value) { listBox_haveInDB.Items.Add(word_for_query); } else if (retrieve["Card"] == DBNull.Value) { listBox_notINDb.Items.Add(word_for_query); } }
I've tried this without the While loop, I've tried variations of if, else, else if and conditions. But for whatever reason the else statement NEVER executes no mater what the first condition is. I've been looking and trying to trouble shoot but the only thing that worked for me was an exception handler:
retrieve.Read(); try { if(retrieve["Card"] != DBNull.Value) { listBox_haveInDB.Items.Add(word_for_query); } } catch { listBox_notINDb.Items.Add(word_for_query); }
This is my way of getting around it. What am I doing wrong?
-
I want it to close when it opens the exe file separately
I have two exe files coded in C# and C++. What I want to do is to download and run the exe coded with C++ from C#. When the C++ application is not brought from the C# application, I do not want it to be launched directly from the downloaded folder. How can I do this?
-
How to filter DataGrid with SelectedItem from ItemsView using WPF?
Quick Summary
I have managed to code up this output so far
XAML
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0"> <DataGrid ItemsSource="{Binding AddressView}"> </DataGrid> </StackPanel> <StackPanel Grid.Column="1"> <ListView ItemsSource="{Binding PersonView}"> <ListView.View> <GridView> <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}" /> <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Name}" /> </GridView> </ListView.View> </ListView> </StackPanel> </Grid>
PersonModel
public class PersonModel { public int Id { get; set; } public string Name { get; set; } public ObservableCollection<PersonModel> GetPersonModels() { ObservableCollection<PersonModel> people = new ObservableCollection<PersonModel>(); people.Add(new PersonModel { Id = 1, Name = "John" }); people.Add(new PersonModel { Id = 2, Name = "Max" }); people.Add(new PersonModel { Id = 3, Name = "Ed" }); return people; } }
AddressModel
public class AddressModel { public int Id { get; set; } public string Address { get; set; } public int PersonId { get; set; } public ObservableCollection<AddressModel> GetAddressModels() { ObservableCollection<AddressModel> addresses = new ObservableCollection<AddressModel>(); addresses.Add(new AddressModel { Id = 1, Address = "Address 1", PersonId = 1 }); addresses.Add(new AddressModel { Id = 2, Address = "Address 1", PersonId = 2 }); addresses.Add(new AddressModel { Id = 3, Address = "Address 2", PersonId = 3 }); return addresses; } }
ViewModel
public class ViewModel : BaseViewModel { // Initializer public ViewModel() { CopyOfPersonModel = new PersonModel(); CopyOfAddressModel = new AddressModel(); RefreshData(); } // Person Models properties private ObservableCollection<PersonModel> _personModels; public ObservableCollection<PersonModel> PersonModels { get { return _personModels; } set { _personModels = value; OnPropertyChanged(); } } public PersonModel CopyOfPersonModel { get; set; } // Person View - Used by the View private ICollectionView _personView; public ICollectionView PersonView { get { return _personView; } set { _personView = value; OnPropertyChanged(); } } // Address Models properties private ObservableCollection<AddressModel> _addressModels; public ObservableCollection<AddressModel> AddressModels { get { return _addressModels; } set { _addressModels = value; OnPropertyChanged(); } } public AddressModel CopyOfAddressModel { get; set; } // Address View - Used by the View private ICollectionView _addressView; public ICollectionView AddressView { get { return _addressView; } set { _addressView = value; OnPropertyChanged(); } } // Method to refresh the data public void RefreshData() { // Refresh the collections from the Model method PersonModels = CopyOfPersonModel.GetPersonModels(); AddressModels = CopyOfAddressModel.GetAddressModels(); // Refresh the views PersonView = CollectionViewSource.GetDefaultView(PersonModels); AddressView = CollectionViewSource.GetDefaultView(AddressModels); } }
Goal
My current goal is to filter the Address View on the left hand side of the MainWindow via the the ListView on the right hand side.
For example: Selected
Id
from the ListView is1
. Then filter the Address View in the DataGrid where PersonId =1
.What I have tried
I added a Filter method and a Search property:
// Filtering private bool Filter(AddressModel address) { return Search == address.PersonId; } private int search; public int Search { get { return search; } set { search = value; OnPropertyChanged(); AddressView.Refresh(); } }
and within my
RefreshData()
at the bottom I have added this line of code to enable filtering.// Filter AddressView.Filter = new Predicate<object>(o => Filter(o as AddressModel));
Problem
This fully works if I bind the
Search
property to a TextBox<TextBox Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
And the DataGrid filters as intended.
But if I try to filter via selected item from ListView like so.. it does not work.
<ListView ItemsSource="{Binding PersonView}" SelectedItem="{Binding Search}" SelectedValue="{Binding Id}"> <ListView.View> <GridView> <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}" /> <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Name}" /> </GridView> </ListView.View> </ListView>
-
.Net Framework C# MVC Spontaneously Redirects to View From Wrong Controller
I have a small project very basic, VS 2013, .Net Framework 4.5 with System.Web.Mvc (5.2.7) installed.
No special routes or authentication; just 3 controllers scaffolded from an EF context. One of the controllers is called DataRoutesController, and another is DataRouteViewFieldsController. DataRouteViewFields is a child (foreign key) of DataRoute. On the Edit page for DataRoute I have a table which lists the related ViewFields, each row with it's own edit and delete buttons.
<button class="btn btn-sm btn-primary" onclick="location.href='@Url.Action("Edit", "DataRouteViewFields", new { id = item.RouteId, name = item.Name })'" title="Edit"> <span class="glyphicon glyphicon-pencil"/> </button>
When I click the button it calls the correct controller and proceeds to the return statement.
public ActionResult Edit(int? id, string name) { DataRouteViewField dataRouteViewField = db.DataRouteViewFields.Find(id, name); return View(dataRouteViewField); }
But then, for some reason I can't comprehend I calls the DataRouteController Index() route and returns the wrong page.
public ActionResult Index() { var dataRoutes = db.DataRoutes.Include(d => d.Connection); return View(dataRoutes.ToList()); }
This behavior is not observed when I don't use the button. If I type the URL to edit the ViewField manually, it works as expected.
When I step though the code (F11) following the return from DataRouteViewFieldController.Edit(...), it proceeds to _ViewStart, then to the Edit.cshtml for DataRouteViewFieldController like it should. When it finishes Edit.cshtml it renders the wrong page. The Edit.cshtml page is largely blank for troubleshooting purposes:
@model ctNetData.DataRouteViewField @{ ViewBag.Title = "Edit"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Edit</h2>
If I add a break to DataRoutesController.Index() then the process starts flipping back and forth between lines of code in DataRouteViewFieldsController.Edit(...) and DataRoutesController.Index() with F11, like it's processing two threads at the same time.
Anyone recognize what's going on here?
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
-
ACE DAO recordsets returning zero fields under vb.net
I'm converting some legacy code that was developed in VBA in access and uses DAO to perform database queries, updates, etc. I need to convert some non-GUI functionality so that it can run unattended without Access running. So I've ported the VBA code to VB.net, using the Access database Engine object library (ACE) to provide the DAO interface.
It works, up to a point: After a certain (unknown) number of times creating and opening (and then closing) recordsets, it starts returning recordsets with the correct number of records, but no members in its Fields collection. So trying to get a field's value using
Fields("Name").Value
throws a "Item not found in this collection" exception.It's not a problem with the particular query: In some cases the exact same query with the exact same parameters worked fine earlier in the execution of the program (with no change to the underlying data). If I rearrange the order of execution of parts of the program, then I get the same kind of error (i.e. recordsets returned with empty Fields collection) with different queries in different parts of the program.
So it looks like there's some kind of bug in the DAO library in which it fails after opening and closing a certain number of recordsets. But it only happens under .Net, not under VBA.
Has anyone come across this problem? Are there any workarounds?
Thanks!
Update: Someone asked that I post some code. As I described above, it doesn't happen at a specific point in the code - I can happen at various places depending on the execution flow. Here's an example of one of the places that it happens. It's a simple function to retrieve an option value from a table of options:
Public Function GetSolverOption(ParameterName As String) As Object ' ' o Gets the value of a solver option. Dim dbsjet As Microsoft.Office.Interop.Access.Dao.Database Dim qdfControl As Microsoft.Office.Interop.Access.Dao.QueryDef Dim rstControl As Microsoft.Office.Interop.Access.Dao.Recordset dbsjet = CurrentDB qdfControl = dbsjet.QueryDefs("Q_Solver Options") qdfControl.Parameters("Q_Parameter").Value = ParameterName rstControl = qdfControl.OpenRecordset GetSolverOption = rstControl.Fields("Value").Value rstControl.Close() End Function
This function gets called many times without any issue, but then the
GetSolverOption = rstControl.Fields("Value").Value
line starts throwing "Item not found in collection" exceptions because the Fields collection is empty. -
Easy Framework for quickly building desktop application?
TL DR: Need framework for quickly developing desktop ERP application. Am good at C#.
Hello, I am working as a junior software developer(C#, .Net), and our current project is to build an ERP software from scratch. Our lead chose WPF in pair with .net core 3 and so far it is a massive shit show. None of us including the lead himself have any front-end experience, and WPF(besides being outdated) proved to be a real pain in the ass. We are miserably failing all the deadlines and app looks like crap. I think only way to save the situation(assuming it's still savable) is to rebuild it on something easier and more managable, until it's too late. What are some of the easiest desktop software development frameworks? To convince my chief, I will have to rebuild what we already have in rather short amunt of time(1 week would be best). We don't have much yet, it's just bunch of forms and grids that are connected to each other. So for instacne there is a Client form, that has several fields binded to values and lists from other tables. We are using microsoft sql for our database. I am proficient in C# and have very basic HTML, CSS experience. I was thinking of Angular + Electron, but I think that is not easy enough to pick up without solid JS and front-end xp. Perhaps Blazor and .Net Core could work too, but don't know much about blazor and how complex it is.
P.S here is a screenshot of one of the forms, so you can have an idea what functionality it should have:
-
adding image to word using word-interop
i am trying to insert an image with the hyper link the below is my code
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application(); WordApp.Documents.Add(); WordApp.Visible = true; Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument; Microsoft.Office.Interop.Word.Range drange = doc.Range(); Microsoft.Office.Interop.Word.InlineShape picture = drange.InlineShapes.AddPicture("c:\\logo.png", Type.Missing, Type.Missing, Type.Missing); // noew add the hyperlink to object of inlineshape drange.Hyperlinks.Add(picture, "http:\\www.google.com", Type.Missing, Type.Missing, Type.Missing, Type.Missing);
but when i run the project i get an error
does any one know why this happens or how i can go about fixing it
-
Is there a way to show 'Show Precedents' dialog in excel programmatically (VBA / VSTO)
I am trying to create a right-click context menu for a worksheet where I need to be able to show cell precedents dialog which appears when we double click the line that appears (not the show precedent arrows function.) similar to this image.
Additional info I have already tried various range options and tried to look for excel Office Fluent User Interface Control Identifiers https://www.microsoft.com/en-us/download/confirmation.aspx?id=50745 but i could not find any that I could use.
-
MS Project - Disable resource
I am creating a Microsoft Project add-in. Depending on the value of a resource's custom text column (let's say Text30), can I disable a resource from showing up when trying to assign it to a task?
So for example, if a row has a Text30 value of
Inactive
, it shouldn't be available to the Project file user to assign it to a task, but it should still be in the Resource Sheet. Below, row 1 would be available as a resource, and row 2 wouldn't show up when assigning resources to a task.