473,226 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

PropertyGrid ErrorProvider


Hello,
I am using ErrorProvider for PropertyGrid control and in case of error I
am doing the following:

SetError(grdInfo, _msgError);

The problem is the the icon is shown near the PropertyGrid in general
and not near the filed which is problematic. I tried this code :

SetError(grdInfo.SelectedGridItem, _msgError); but this code is not
being compiled.

How can I show he icon near the corruptedd field of PropertGrid?

Thank u!

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
4 6438
ErrorProvider only supports the control to which it's bound and PropertyGrid
doesn't expose child controls so you will be unable to provide this
functionality.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"csharpula csharp" <cs*******@yahoo.comwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
>
Hello,
I am using ErrorProvider for PropertyGrid control and in case of error I
am doing the following:

SetError(grdInfo, _msgError);

The problem is the the icon is shown near the PropertyGrid in general
and not near the filed which is problematic. I tried this code :

SetError(grdInfo.SelectedGridItem, _msgError); but this code is not
being compiled.

How can I show he icon near the corruptedd field of PropertGrid?

Thank u!

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2
For info, if you don't mind doing some legwork (involving a lot of
IErrorInfo etc), you should be able to use IPropertyValueUIService to
accomplish this. This is the same interface that dependency properties
use to put the little blue glyph by the property name, and I *suspect*
(without checking) that it is also what certain bindings use
(settings-bound, for example, puts a glyph on the property name).

If I recall, there is a demo on CodeProject that shows how to do this.

I can't guarantee it will be easy; so if it sounds useful but beyond
your current experience with System.ComponentModel, let me know; I might
be able to knock something together on the train... ;-p

Marc
Jun 27 '08 #3
that shows how to do this.

To clarify - it shows how to put glpyhs onto properties in PropertyGrid;
it doesn't specifically show how to display validation information...

Marc
Jun 27 '08 #4
Ah, what the heck... ;-p

Note this draws on Carsten Zeumer's CodeProject example
(PropertyGridExWinForms).

Marc

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;

// sample entity class
public class Foo : IDataErrorInfo
{
public string Name { get; set; }
[DisplayName("Date of Birth")]
public DateTime DateOfBirth { get; set; }

string IDataErrorInfo.Error
{
get { return null; }
}
private static void AddError(ref StringBuilder sb, string message) {
if(!string.IsNullOrEmpty(message)) {
if(sb == null) sb = new StringBuilder();
sb.AppendLine(message);
}
}
string IDataErrorInfo.this[string columnName]
{
get {
StringBuilder err = null;
switch (columnName)
{
case "Name":
if (string.IsNullOrEmpty(Name)) AddError(ref err,
"Name cannot be blank");
break;
case "DateOfBirth":
if (DateOfBirth == DateTime.MinValue) AddError(ref
err, "Date of Birth cannot be blank");
if (DateOfBirth DateTime.Now) AddError(ref err,
"Date of Birth cannot be in the future");
break;
}
return err == null ? null : err.ToString();
}
}
}
static class Program
{
// used to show error notifications
private static readonly PropertyValueUIItemInvokeHandler
UIItemNullHandler = delegate { };
private static readonly Image UIItemErrorImage =
SystemIcons.Error.ToBitmap();
static void VerifyDataErrorInfo(ITypeDescriptorContext context,
PropertyDescriptor propDesc, ArrayList valueUIItemList)
{
IDataErrorInfo errInfo = context == null ? null :
context.Instance as IDataErrorInfo;
string propName = propDesc == null ? null : propDesc.Name;
if(errInfo != null && !string.IsNullOrEmpty(propName)) {
string errMsg = errInfo[propName];
if(!string.IsNullOrEmpty(errMsg)) {
valueUIItemList.Add(new
PropertyValueUIItem(UIItemErrorImage, UIItemNullHandler, errMsg));
}
}
}
// sample app
static void Main() {

Foo foo = new Foo();
Application.EnableVisualStyles();

using(Form form = new Form())
using (PropertyGrid grid = new PropertyGrid())
{
SimpleSite site = new SimpleSite
{
Name = "GridSite",
Component = grid
};
GlyphService svc = new GlyphService();
svc.QueryPropertyUIValueItems += VerifyDataErrorInfo;
site.AddService<IPropertyValueUIService>(svc);
grid.Site = site;
grid.Dock = DockStyle.Fill;

grid.SelectedObject = foo;
form.Controls.Add(grid);
Application.Run(form);
}

}

}

public sealed class GlyphService : IPropertyValueUIService
{
public event EventHandler PropertyUIValueItemsChanged;
public event PropertyValueUIHandler QueryPropertyUIValueItems;

public PropertyValueUIItem[]
GetPropertyUIValueItems(ITypeDescriptorContext context,
PropertyDescriptor propDesc)
{
ArrayList list = null;
if (QueryPropertyUIValueItems != null)
{
list = new ArrayList();
QueryPropertyUIValueItems(context, propDesc, list);
}
if (list == null || list.Count == 0)
{
return new PropertyValueUIItem[0];
}
PropertyValueUIItem[] result = new PropertyValueUIItem[list.Count];
list.CopyTo(result);
return result;
}
public void NotifyPropertyValueUIItemsChanged()
{
if (PropertyUIValueItemsChanged != null)
{
PropertyUIValueItemsChanged(this, EventArgs.Empty);
}
}
void
IPropertyValueUIService.RemovePropertyValueUIHandl er(PropertyValueUIHandler
newHandler)
{
QueryPropertyUIValueItems -= newHandler;
}
void
IPropertyValueUIService.AddPropertyValueUIHandler( PropertyValueUIHandler
newHandler)
{
QueryPropertyUIValueItems += newHandler;
}

}
public sealed class SimpleSite : ISite, IServiceProvider
{
public IComponent Component { get; set; }
private readonly IContainer container = new Container();
IContainer ISite.Container { get { return container; } }
public bool DesignMode {get;set;}
public string Name {get;set;}
private Dictionary<Type, objectservices;
public void AddService<T>(T service) where T : class
{
if (services == null) services = new Dictionary<Type, object>();
services[typeof(T)] = service;
}
public void RemoveService<T>() where T : class
{
if (services != null) services.Remove(typeof(T));
}
object IServiceProvider.GetService(Type serviceType)
{
object service;
if (services != null && services.TryGetValue(serviceType, out
service))
{
return service;
}
return null;
}
}
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martijn Leine | last post by:
I am using an errorprovider and a datagrid component on a form. I use the errorprovider to display error hints in the grid, in the case the entered data by the user is checked and not found Ok....
6
by: M O J O | last post by:
Hi, How do I check if an ErrorProvider has errors? Take for example this code... (err = ErrorProvider...) Public Sub Test If TextBox1.Text= "" Then
0
by: Issac | last post by:
Hi, I am writing a program which will be used in Win2000 and Win98 platform. The program include a Form (called myForm) which has a TextBox, Tooltip, Errorprovider and a Button. Tooltip...
3
by: Jeppe Jespersen | last post by:
I read the following - regarding the ErrorProvider control - in the MOC Course Material for course 2373: "You can set your own error messages manually, as shown in the following example, or when...
2
by: Lenster | last post by:
I'm having problems using the errorprovider in VB.NET to automatically display an error icon next to textboxes bound to the same dataset as the errorprovider. The sequence of events is : ...
4
by: ljlevend | last post by:
I have the following issues: 1. I want to make it so that ToolTips never go away once they are shown until the user moves the mouse outside of the control for which the ToolTip is assigned. It...
5
by: Alvaro Lamas | last post by:
I have a problem with the ErrorProvider with a mdi interface, I have a MDI form which opens a child form, that child form uses the errorprovider to show the problems with the data entry. The...
6
by: Steve Teeples | last post by:
Can someone show me an example of how to place a "CheckedListBox" property within a PropertyGrid? -- ----------- Thanks, Steve
4
by: Freeon | last post by:
How do I capture the hover event on the ErrorProvider control? I created a custom control and inherited the ErrorProvider. Problem is I don't know which method to override to capture the hover...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.