I am working with an image column on dataGridView:
As shown in the attached picture, when I click on 'browse' I can choose a file from the dialog window.
What I want...
is to make the image on the 'Files' image-column to link to the chosen file (to get the file open when the user clicks on the image).
I have no idea how to make that happen. Could anyone give me a direction?
First You can create your own Class and put in this class Property for File Path
I've created example :
public class MyClass
{
public string Name{get;set;}
public string FilePath{ get; set; }// Here i put The path and it will not appear in the Grid will just show the first item
}
in DataGrid there is an event called SelectionChanged you can add this code there
if (DG.CurrentColumn.Header.ToString() == "Name")
Process.Start((DG.SelectedItem as MyClass).FilePath);
when i select the item it will open the folder you can put instead of ("Name") your column name ("Brows")
Related
I want to make a user control which acts like a TabControl but the tab page buttons should have big images. Therefore I want to have a property Images which adds images to the user control like an ImageList. For every image, the user control then generates a PictureButton and a corresponding panel. For that reason I added an ImageList to the user control and I've also tried to just add a collection of Image.
The problem is, that I cannot access this ImageList from the main form designer.
I've tried the following properties:
public Collection<Bitmap> Images { get; set; }
// ----
public ImageCollection Images { get; set; }
// ----
public List<Bitmap> Images { get; set; }
// ----
public ImageList Images { get; set; }
When I try to add an image to a Collection<Bitmap> or List<Bitmap> in the designer then Visual Studio crashes. I cannot use Image instead of Bitmap.
I know that I could use TabControl itself and give each TabPage an image, but I don't like the look of it.
So what's the best way to add a collection of images to a user control from the main form?
I am trying to access that the text of a clicked button.But ıt always returns the text of first child of gameObject.But I want to access the text of clicked child.
I tried the code below:
transform.gameObject.GetComponentInChildren<Button>().GetComponentInChildren<Text>().text;
You can make a custom class which references the text you care about:
public class ButtonExtras : MonoBehaviour
{
public Text buttonText; // assign this in the inspector
}
then elsewhere:
GetComponentInChildren<ButtonExtras>().buttonText.text = "hello!";
So i assume that your shown line of code is in a script lying on some general object (and not on every single button). So what you could do is to take a button as parameter like this:
void HandleText(Button button){
Text text = button.getComponentInChildren<Text>();
// do whatever you want to do with the text here
}
Then for every button you could add this method to OnClick listernes with the button itself as parameter. Hope that makes sense
I found a simple solution:
GameObject.Find(EventSystem.current.currentSelectedGameObject.name).GetComponent<Button>().GetComponentInChildren<Text>().text
Thank you to everyone who shared their ideas.
I'm french, so sorry for my bad english... But I hope that you will help me ;)
I'm developing a soft in c# with lot of information store in DB, like information about people.
I want display these information with a beautiful UI, like that :
For that, I created :
a first panel in Visual
a class for create sub panel dynamically
I make a loop and for each person, I call a method "createPanel" with the information of each person, and these sub panels created are added to the parent panel. The ID of each person is store in the "tag" parameter of the sub panel.
All work fine, but I don't really know how to add event in each sub panel.
As you can see in the link above, the user can click on a bookmark, or a icon for show a menu (the round with 3 point = icon "menu").
My question is how to add event for each sub panel dynamically ? For example I want display a menu for each sub panel when I click on the icon "menu", get the id store in the "tag" of the sub panel, and show a new form for manage information.
Thx for your help, I can add my code if necessary :)
Make a own user control for the panels you want to display containing all the controls from the toolbox you need.
public partial class MyControl : UserControl
{
...
}
In "MyControl" you define events for all things that can happen and must be handled externally of the control. Same as e.g. "SelectedIndexChanged" for combobox.
Your control class would then look like this:
public partial class MyControl : UserControl
{
public event EventHandler<MyImportantEventA> OnImportantThingHappend;
//Event-Invoker
protected virtual void OnOnImportantThingHappend(MyImportantEventA e)
{
OnImportantThingHappend?.Invoke(this, e);
}
}
//Data of your event. Customize as you like/need.
public class MyImportantEventA : EventArgs
{
public string Message { get; set; }
}
When you add your control dynamically, bind to the event(s) of your control:
myUserControl.OnImportantThingHappend += DoSomethingWithEvent;
Things the control can handle it self, don't need to be exposed as events.
E.g.:
"Close" may be something that must be handled externally. You need to remove the control, rearange you controls etc.
"Show Details" probably is something that can be handled completely inside of your control. Your control shows a message box or a fancy tooltip.
Something happens strange... I have a Receipt.cs class in my project. When i try to bound my datagridview to this class then there is no option of Receipt.cs in Choose Data Source Option.
In my previous project everything works well in visual studio. I couldn't understand why this happens in my new project.
Here is Image, No option for Receipt.cs But my project has Receipt.cs Class
Here is my Receipt.cs Class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Store_Management_System
{
public class Receipt
{
public int Id { get; set; }
public string ProductName { get; set; }
public double Price { get; set; }
public int Quantity { get; set; }
public string Total { get { return string.Format("{0}$", Price * Quantity); } }
}
}
References in my Project. May be i am missing some reference?
The Class should appear in Object Data Source List after its being compiled. It looks you have not recompiled/build the project containing the Receipt class.
-Thanks
After creating Receipt.cs class, I rebuild the project but build was not successful as there is some little error (But not in Receipt.cs class).
I removed the error and make Successful Build, Then everything goes Fine...!!!
this was left unsolved by people. I just want to share the solution to this.
Go to the properties of the datagridview and click on the databindings property.
Choose (Advanced) and click on the ellipses.
Click on the Binding combo box then
Click on the "Add Project Data Source.
Choose the Object and click on "Next".
Then expand your program and choose the class you created.
Click on "Finish" then "OK" button.
Now click on the small triangle button on the datagridview and
hit on the combo box again and see the "Other Data Sources..."
is there a way to quick copy selected control name to paste it then to text editor? i have lot of control that i have to set my class property to, then i have to select each one then click on properties, then select name and ctrl+C. Is there no way to just select control on designer then ctrl+C+someOtherKey end voila i can paste it to text editor ? (or even maybe there is a way to quick copy of name of all selected contols :) ?
I use visual studio proffesional 2012 (going to change it to 2015 in near future).
What I would do is create my own custom extention. Say for example that you want all your Buttons to be green and say "Zelda". You would create the following class.
public GreenZeldaButton : Button
{
public GreenZeldaButton()
{
BackColor = Color.Green;
Text = "Zelda";
}
}
Then you have to get this into the Toolbox, I'm not sure of the proper method but what I do is create a new instance in the form contructor. As so:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
new GreenZeldaButton();
}
}
And then press F5 to debug in order to add the new control to the toolbox. Then you can drag and drop the new control from the toolbox to the Designer. This is what I do when I want multiple copies of a control with specific properties. Hope this helps ^_^. P.S. You can remove the "new GreenZeldaButton();" thing (or your alternative obviously) after the control has been added to the toolbox.