|
Hello,
I'm hoping someone can help me out here.
I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do.
What I want to do is very simple:
(1) I have a list of class instances thus:
List<MyClass> classList;
(2) I want each MyClass member of classList to be represented as a row in my DataGridView
(3) I want to show only a subset of the class parameters, for example:
public class MyClass<br />
{<br />
private string name;<br />
private int anumber;<br />
<br />
public String Name<br />
{<br />
get { return (name); }<br />
set { name = value; }<br />
}<br />
<br />
public int Number<br />
{<br />
get { return (anumber); }<br />
set { anumber= value; }<br />
}<br />
}<br />
I think that sums it up. No SQL, nothing just a nice list of data that I want to display.
Can anyone help? Many thanks!!
|
|
|
|
|
My formating didn't come out properly, the first line of code should read:
List<MyClass> classList = new List<MyClass>();
classList.Add(new MyClass("Fred"));
classList.Add(new MyClass("Wilma"));
etc
|
|
|
|
|
I'm looking for a way to separate sections of text with horizontal lines in a textbox or another control. My nice-to-have would probably be a TableLayoutControl with a row containing a textbox for each section, allowing independent horizontal scrolling for each section, but I would settle for a textbox modded to act like the old code windows in VB6, with thin horizontal lines separating each section.
My second wish, in the ideal solution, is for the textboxes to autosize their height based on the text they contain.
Any suggestions please?
I do not believe they are right who say that the defects of famous men should be ignored. I think it is better that we should know them. Then, though we are conscious of having faults as glaring as theirs, we can believe that that is no hindrance to our achieving also something of their virtues. - W. Somerset Maugham
My New Blog
|
|
|
|
|
Brady Kelly wrote: separate sections of text with horizontal lines in a textbox or another control.
Try to use RichTextBox control and insert a horizontal-line bitmap from some web page.
Brady Kelly wrote: autosize
CP is full of such solutions, the easiest way is to handle TextChanged:
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Width = (int)CreateGraphics().MeasureString(textBox1.Text, textBox1.Font).Width + 10;
}
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
I want to know about vurtual graphic adapter in depth in respect to vista, do any body have any link or any article about it.
thanx
prashant jain
|
|
|
|
|
hi all,
my problem is how to include a checkbox as the first column in datagrid(not in Datagridview)in windows application for .net 2003 .pls suggest me its very urgent
ksf
|
|
|
|
|
u include a checkbox in datagrid by defining its datatype boolean
exp.
dc = New DataColumn("Is Male")
dc.DataType = System.Type.GetType("System.Boolean")
dc.DefaultValue = false
dc.ReadOnly = True
dt.Columns.Add(dc)
here dt is datatable.
Ghazanfar Ali
Programmar (MSTS,MCPD)
|
|
|
|
|
I've got a question for you. See if you can help.
Our winform application does some calculations on the main form. Basically, an input (say IN) is entered and application extracts data from data sources and displays it in text boxes and grids through a main event which is fired by pressing a button. The data is unique to every IN (input) we enter.
The Need:
The goal is to open multiple forms and compare data of different INs side by side.
The Problem:
When I open a new form (or multiple forms) through MDIParent menu, instead of keeping the data of INs separate, the main event is fired in the default form. As a result, the data are over written and the the most recent data is processed and displayed in all the forms. Meaning, we end up with same data in multiple forms. We want the data to be displayed in individual forms.
Question:
Do you know what might be happening here?
Appreciated.
|
|
|
|
|
basi0014 wrote: Do you know what might be happening here?
You have a serious desgin flaw in your app. No, really.
Each form should be getting it's own set of data, but it's not. It appears that every child form is looking at the same "IN". Since we have no idea what you mean by "IN", it's impossible to tell you waht's going on.
Each copy of this child form should be maintaining it's own copy of whatever objects you're using to hold the data.
|
|
|
|
|
Dave Kreskowiak wrote: You have a serious desgin flaw in your app.
I agree. Sounds likes the OP needs to relook at how things should be done.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
if i use a dll in my project(i don't have the code of this dll.and i have receipt the new version of the dll but
some methods are changed.the compiler don't throw an error but while running the project a method not found exception appear.
Note :can i compile this dll using command prompt?
dghdfghdfghdfghdgh
|
|
|
|
|
ellllllllie wrote: can i compile this dll using command prompt?
It is already compiled.
The compiler should pick up the changes for where ever else it is used, unless you are building the other assemblies against the old DLL.
|
|
|
|
|
I am in the process of designing a generic 'record maintenance' toolbar class containing the 'standard' add/edit/delete/save/cancel buttons. I notice that the VS toolbox already has a bindingnavigator control which already has some of the functionality that I require (although I don't require the navigation buttons).
Which control should I go for? As far as I can see the bindingnavigator is just a glorified toolbar bound directly to a datasource, but I may be missing something.
Can I subclass a toolbar/bindingnavigator visually or does it have to be done in code? I am using C# with VS2005 express.
TIA
Alan
|
|
|
|
|
aharrisreid wrote: I am in the process of designing a generic 'record maintenance' toolbar class containing the 'standard' add/edit/delete/save/cancel buttons. I notice that the VS toolbox already has a bindingnavigator control which already has some of the functionality that I require (although I don't require the navigation buttons).
Which control should I go for? As far as I can see the bindingnavigator is just a glorified toolbar bound directly to a datasource, but I may be missing something.
Can I subclass a toolbar/bindingnavigator visually or does it have to be done in code? I am using C# with VS2005 express.
You can just use Windows Forms' BindingSource and create a decent ToolStrip (previously known as ToolBar in .NET 1.x), with your own buttons with custom actions.
Any data binding applications in Windows Forms can do navigating by just using BindingSource with a valid DataSource such as DataSet or DataTable.
Start from this:
http://msdn2.microsoft.com/en-us/library/ef2xyb33.aspx[^]
Eriawan
|
|
|
|
|
Hi kuyak2000, thanks for the reply.
You can just use Windows Forms' BindingSource and create a decent ToolStrip (previously known as ToolBar in .NET 1.x), with your own buttons with custom actions.
The problem with the BindingSource is that I don't require the navigation buttons, which only leaves the add and delete buttons, so I would have to add my own edit/save/cancel buttons. It might make more sense for me to create my own customised toolstrip.
Regards,
Alan
|
|
|
|
|
aharrisreid wrote: The problem with the BindingSource is that I don't require the navigation buttons, which only leaves the add and delete buttons, so I would have to add my own edit/save/cancel buttons. It might make more sense for me to create my own customised toolstrip.
Using VS 2005 IDE, you can just add BindingSource by dropping from toolbox, and then start to create your own ToolStrip with your own data manipulation buttons. Dropping BindingSource doesn't create new BindingNavigator on your Form.
regards,
Eriawan
|
|
|
|
|
Hi Eriawan, thanks for the reply.
kuyak2000 wrote: Using VS 2005 IDE, you can just add BindingSource by dropping from toolbox, and then start to create your own ToolStrip with your own data manipulation buttons. Dropping BindingSource doesn't create new BindingNavigator on your Form.
I think I understand what you are saying, but how do I use toolstrip buttons in conjunction with the bindingsource to achieve the required action? For example, say I have a 'Save' button on the strip. What sort of code would it have called from the Click method which saves data back to the database? Can you point me to any examples?
Any help would be appreciated.
Alan
|
|
|
|
|
It's quite easy.
- First you have to validate the form using Form.Validate() method,
- End the edit of bindingsource used using BindingSource.EndEdit() method.
- Save the datasource. If you're using TableAdapter, just use Update() method
Good luck!
best regards,
Eriawan
|
|
|
|
|
Hi Eriawan,
That was easier than I thought it would be. I'll try it out asap..
Thanks,
Alan
|
|
|
|
|
I have a DataGridView on a windows form. If a user clicks on a cell, a property gets the current row and then populates data in another form. When a cell is highlighted, if a user double clicks on the columnheaders the modal form loads with the data from the highlighted row. I want to stop users from being able to double click on the column headers. Does anyone have any suggestions on how I could do this?
Thanks,
Taylor
|
|
|
|
|
Your question is not very clear to me. If you want to do something when you double click on a cell (and avoid doing anything if the user double clik on the header)
you can do something like this,
private void gvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int miHitRow = Convert.ToInt32(e.RowIndex);
if (miHitRow < 0)
return;
//your code
}
|
|
|
|
|
Hey,
I need to share variables among forms in the Web session (or application) manner. I used to have some code - which I don't have now- that implements the singleton design pattern and allows adding and retrieving objetcs this way :
Application["MyObject"] = object;
Can you help?
Thanks.
|
|
|
|
|
I would use a static class with a static member with an indexer:
public static class SC
{
private static SettingsClass settings = new SettingsClass();
public static SettingsClass Application
{
get { return settings; }
}
public class SettingsClass
{
Dictionary<string, object> settings = new Dictionary<string,object>();
public object this[string id]
{
get
{
return settings[id];
}
set
{
if (!settings.ContainsKey(id))
settings.Add(id, value);
else
settings[id] = value;
}
}
}
}
add use it this way:
SC.Application["key"] = someObject;
Hope it helps anyhow.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hello,
Thanks gajatko for your help.
Your code uses generics and SettingsClass that are not available in C# 1.1. How can I rewrite it to make it work in VS2003?
Thanks.
-- modified at 10:25 Monday 24th September, 2007
|
|
|
|
|
Implement System.Collections.DictionaryBase.
public static class SC
{
private static SettingsClass settings = new SettingsClass();
public static SettingsClass Application
{
get { return settings; }
}
public class SettingsClass
{
StringObjectDictionary settings = new StringObjectDictionary();
public object this[string id]
{
get
{
return settings[id];
}
set
{
if (!settings.ContainsKey(id))
settings.Add(id, value);
else
settings[id] = value;
}
}
}
}
class StringObjectDictionary : System.Collections.DictionaryBase
{
public StringObjectDictionary() : base()
{
}
public void Add(string key, object value)
{
base.Dictionary.Add(key, value);
}
public object this[string key]
{
get { return base.Dictionary[key]; }
set { base.Dictionary[key] = value; }
}
public bool ContainsKey(string key)
{
return base.Dictionary.Contains(key);
}
}
Edit: The alternative is use of environment variables (Environment.SetEnvironmentVariable ). They also are session-like.
-- modified at 11:16 Monday 24th September, 2007
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|