Binding Source Control Datasource property not responding at design time. VS
I am trying to bind an object to the data source property of a Binding source control but when I click on the property at design time in VS 2019, nothing happens. There seems to be some type of activity because the pc freezes for a short while then nothing happens. Trying this on the same project but different VS version 2017, different machine, brings up the data source dialog, allows to navigate to the data object, select it but the data source property remains empty. It does not attach the object.
See also questions close to this topic
-
Convert CSV file data from any language to English in C#
I would like to convert CSV file data from multi languages such as Spanish, Russian, European etc to English language in C# program.
Convert all characters like Ó, É to English characters.
Thanks.
-
I get an error when solving this problem, How can I fix?
I am trying to solve the Climbstairs problem but in reverse, where I want to know the number of steps I have to take to go down.
I can go down 1, 2, 3 or 4 steps at the same time. That is, if I am at step i, I can go down to step i - a for any of the values 1, 2, 3 or 4 of a.
I have the following code but I don't know what happens:
I got this error: System.IndexOutOfRangeException in this line:
steps[i] += steps[i - a];
Why I have this error?
public static int DownStairs(int n) { int[] steps = new int[n + 1]; steps[n] = 1; steps[n - 1] = 1; for (int i = n-2; i>=0; i--) { for(int a = 1; a<=4; a++) { steps[i] += steps[i - a]; } } return steps[n]; } static void Main(string[] args) { int n = 5; DownStairs(n); }
-
How to delete multiple blank lines in a WPF DataGrid imported from an Excel file
I have a WPF DataGrid which I fill with imported data from an Excel file (*. Xlsx) through a class, the problem is that multiple blank lines are added to the end of the DataGrid that I don't see how to delete. I attach my code.
<DataGrid Name="dgvMuros" Height="210" Margin="8" VerticalAlignment="Top" Padding="5,6" ColumnWidth="50" IsReadOnly="False" AlternatingRowBackground="Azure" GridLinesVisibility="All" HeadersVisibility="Column" Loaded="dgvMuros_Loaded" CellEditEnding="DataGrid_CellEditEnding" ItemsSource="{Binding Data}" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" > </DataGrid>
With this method I import the data from the Excel file.
public void ImportarMuros() { ExcelData dataFronExcel = new ExcelData(); this.dgvMuros.DataContext = dataFronExcel; txtTotMuros.Text = dataFronExcel.numMuros.ToString(); cmdAgregarMuros.IsEnabled = false; cmdBorrarMuros.IsEnabled = false; cmdImportar.IsEnabled = false; } public class ExcelData { public int numMuros { get; set; } public DataView Data { get { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Range range; workbook = excelApp.Workbooks.Open(Environment.CurrentDirectory + "\\MurosEjemplo.xlsx"); worksheet = (Excel.Worksheet)workbook.Sheets["DatMuros"]; int column = 0; int row = 0; range = worksheet.UsedRange; DataTable dt = new DataTable(); dt.Columns.Add("Muro"); dt.Columns.Add("Long"); dt.Columns.Add("Esp"); dt.Columns.Add("X(m)"); dt.Columns.Add("Y(m)"); dt.Columns.Add("Dir"); for (row = 2; row < range.Rows.Count; row++) { DataRow dr = dt.NewRow(); for (column = 1; column <= range.Columns.Count; column++) { dr[column - 1] = Convert.ToString((range.Cells[row, column] as Excel.Range).Value); } dt.Rows.Add(dr); dt.AcceptChanges(); numMuros = dt.Rows.Count; } workbook.Close(true, Missing.Value, Missing.Value); excelApp.Quit(); return dt.DefaultView; } } }
-
How to remove the border of a DateTimePicker Control?
Is it possible to remove the border of DateTimePicker?
Because I'm trying to make it border-less for design. -
WinForms Server To Handle ASP.NET Web
I am about to convert my Winforms applications to an ASP.NET Web Application. The only question I have is the following:
My Winforms application connects to a server via TCP/IP connection (TCPClient), and handles all requests and commands through my own custom protocols (Strings sent that are validated server side and sent back to client)
Can I keep this same Server to handle the requests from my ASP.Net Web Application (I plan on using the same protocol)?
Will there be anything I have to change within the server? How different is migrating a Winforms application to an ASP.Net application?
Do you suggest I use WebForms or MVC?
-
New Issue for previously working code to find all AD groups a user is a member of (Some or all identity references could not be translated)
I have code that returns a list of all AD Groups the current user of a Windows Forms application is a member of. This is used to determine access rights. It has worked fine for a while, but all of the sudden it does not work and returns the error "Some or all identity references could not be translated". Note this error does not occur when I am in the Virtual Machine debugging the code, but only when I publish it and try to access it from our company's shared drive. It may be due to some network security change and be related to domain permissions or something similar, but my IT Department is not helpful in this regard.
The error is on the line below:
Dim group As String = id_ref.Translate(GetType(NTAccount)).Value
The entire function is below:
Shared Function GetGroupNames() As List(Of String) 'Returns a list of all groups the current user is a member of. Called from CheckAccess. Dim groups As New List(Of String) For Each id_ref As IdentityReference In WindowsIdentity.GetCurrent().Groups Dim group As String = id_ref.Translate(GetType(NTAccount)).Value If group.Contains("\") Then 'Remove unneeded domain info. group = group.Split("\")(1).ToLower End If groups.Add(group) Next Return groups End Function
-
Is it possible to have an Android Studio project that also builds on Visual Studio 2019?
I looked a lot into it, and it appears there's no way to keep synced the
build.gradle
file from Android Studio andbuild.gradle.template
from Visual Studio, same thing forAndroidManifest.xml
andAndroidManifest.xml.template
andsettings.gradle
andsettings.gradle.template
andgradle-wrapper.properties
andgradle-wraper.properties.template
.Am I missing something or is there a way? It would be super cool to have both in a project since some people prefer VS and others prefer AS to work with Android projects.
Is there maybe a magic to keep autogenerating the
app.androidproj
file and the templates from the Android Studio originals? -
In Visual Studio, are there code comments for C++ like there are for C#?
In Visual Studio with C# you can hover over most of the default code and it will give you a pop-up description that tells you what the code is. I recently started learning C++ and am very much missing that helpful pop-up info. There's a pop-up, but it only contains the method signature, none of the other helpful descriptions that says what the thing is for.
All I could find were instructions on how to make my own, but I'm trying to find out if there are any default ones or maybe a tool I can add that will help.
Edit: Here are a couple pictures to explain what I mean. I don't want to make my own tool tips, I'm trying to find out if there's something that will help me understand what a function, field, etc is for while scrolling through them while in Visual Studio.
C# tool tip:
-
How would I access an Image file inside my soloution in C# WPF
I am trying to set the background of a programmatically created Canvas, Using the following method:
Canvas Object = new Canvas(); Object.Background = new ImageBrush(new BitmapImage(new Uri("pages/Asset/Untitled 6.png", UriKind.Relative)));
This URI WOULD WORK In XAML, for setting a background image however in C# the scope seems to be in a different folder.
-
Creates an Object of the specified type at design-time and adds it to the design document (XAML) in WPF
I need to write design-time part of my Control.
In the code I need to create new Object (TextColumn) and add it to the Collection (Columns). The changes must be reflected in XAML document. How can I do it?
In WinForms I used IDesignerHost.CreateComponent method.
WinForms
IServiceProvider srvProvider; IDesignerHost host = (IDesignerHost)srvProvider.GetService(typeof(IDesignerHost)); PropertyAxisBar band = (PropertyAxisBar)host.CreateComponent(itemType);
But I cant find any Documentation or Example for WPF.
I explored documentation - WPF Designer Extensibility https://docs.microsoft.com/en-us/previous-versions/bb546938(v=vs.110)?redirectedfrom=MSDN
and Demo project - XAML Designer Extensibility Documents & Samples https://github.com/microsoft/xaml-designer-extensibility
Unfortunately, these sections do not describe how to create objects that reflect changes in a XAML document.
-
Modify property serialization/deserialization in WinForms Form1.resx file
I have a custom class and made the same serialization as System.Drawing.Image, by implementing ISerializable interface and two methods:
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) to give the serializer my data in the format I need.
- A constructor in my class: protected MyClass(SerializationInfo info, StreamingContext context)
[Serializable] [TypeConverter(typeof(MyClassTypeConverter))] [Editor(typeof(MyClassEditor), typeof(UITypeEditor))] public class MyClass : MarshalByRefObject, ISerializable, ICloneable, IDisposable
A have added my class as a property to a custom button -> MyButton.MyClass The problem is that at design time when I set MyClass the serializer writes the assembly name and version in the RESX file of the form before my custom serialized object. Here is how it looks like:
<assembly alias="MyAssembly" name="MyAssembly, Version=2020.1.1, Culture=neutral, PublicKeyToken=XXX" /> <data name="myButton1.MyClass" type="MyAssembly.MyClass, MyAssembly"> <value>Some long text data</data> </data>
After a new release my clients started having this exception:
System.InvalidCastException: '[A]MyAssembly.MyClass cannot be cast to [B]MyAssembly.MyClass. Type A originates from 'MyAssembly, Version=2020.1.1, Culture=neutral, PublicKeyToken=XXX' in the context 'Default' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\...
Here is the designer file:
private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2)); this.myButton1 = new MyAssembly.MyButton(); this.SuspendLayout(); // // myButton1 // this.myButton1.Location = new System.Drawing.Point(5, 5); this.myButton1.Name = "myButton1"; this.myButton1.Size = new System.Drawing.Size(200, 25); this.myButton1.MyClass = ((MyAssembly.MyClass)(resources.GetObject("myButton1.MyClass"))); this.myButton1.TabIndex = 0; this.myButton1.Text = "myButton1";
The assembly where type MyClass is located is already loaded, because MyButton is located in the same assembly. So I do not need the RESX file to contain information about the assembly. Currently I cannot find a solution on my own and I am thinking of two options:
- How can I prevent serializing the <assembly alias="MyAssembly"...> in the resx file of the form?
- Can I load MyClass from the resx file without loading the described assembly?