|
Hi
My MainForm's got 3 panels, top/left and bottom. When I click button on MainForm the LeftPanel gets populated by Form2. When I click a bottun on Form2 I need to add another Form3 to the TopPanel on the MainForm?
Thanks
DM
|
|
|
|
|
Make classes Form2 and Form3 extend UserControl, not Form. Then your click code is simple...
public class MainForm : Form {
private Form2 m_Form2 = new Form2();
...
public MainForm() {
InitializeComponent();
m_Form2.Dock = DockStyle.Fill;
}
...
public Panel TopPanel {
get { return panel_Top; }
}
...
private void btn_AddForm2_Click(object sender, EventArgs e) {
panel_Left.Controls.Clear();
panel_Left.Controls.Add(m_Form2);
}
...
}
public class Form2 : UserControl {
private Form3 m_Form3 = new Form3();
...
public Form2() {
InitializeComponent();
m_Form3.Dock = DockStyle.Fill;
}
...
private void btn_AddForm3_Click(object sender, EventArgs e) {
MainForm parentForm = this.ParentForm as MainForm;
if (parentForm == null) return;
parentForm.TopPanel.Controls.Clear();
parentForm.TopPanel.Controls.Add(m_Form3);
}
}
Hope this helps!
Jeff
|
|
|
|
|
I am attempting to override RichTextBox class and am overloading the appropriate methods to allow drag-drop text. If the source textboxes are NOT readonly, this process works fine. However, when I try to perform a drag-drop from a readonly textbox to a writable textbox, my code fails. I know that it is failing because I am setting the e.Effect value to DragDropEffects.Move, when the only effect that I allow is DragDropEffects.Copy. What I don't understand is how I can, at runtime, determine if DragDropEffects.Move is available as an option. In both my event handlers for DragEnter and DragOver, e.AllowedEffect appears to ALWAYS be (Move | Copy | Select) regardless of what I set it to in the call to DoDragDrop(). I know there is a way to see what options are available, because I can drag from my readonly textboxes into wordpad. I am also wondering why, when I override the ReadOnly property, does the RichTextBox NOT get displayed in the readonly style? It is showing up as a normal textbox, despite it being defined as readonly. Thanks in advance for your help.
-Jeff
-- modified at 17:49 Friday 7th September, 2007
|
|
|
|
|
Skippums wrote: e.AllowedEffect appears to ALWAYS be (Move | Copy | Select) regardless of what I set it to in the call to DoDragDrop(). I know there is a way to see what options are available,
That's because your supposed to be setting the available options, not looking for them. The destination of a drag'n'drop operation dictates what options are available, not the sender.
|
|
|
|
|
OK, so the receiver sets the operation... But why do I send the allowable operations with the call to "DoDragDrop(data, DragDropEffects.Copy)". Isn't the second argument the allowable operations? Is there no way to get at the value set in this manner? Right now, what is happening is that in my target, the operation is being set to DragDropEffects.Move (in the DragEnter event), which results in the graphic being DragDropEffects.None since DragDropEffects.Move | DragDropEffects.Copy == 0. Therefore, my target textbox needs to know that Move is not supported. There has to be some way to do this. Please help! Thanks,
-Jeff
|
|
|
|
|
I have several collections derived from ReadOnlyCollection<t>.
For reasons of time and resource management, I don't want to automatically populate the underlying lists unless the collection or one of its properties/methods is actually accessed by some code.
This I accomplish by replacing each method of the ReadOnlyCollection with a "new" method in the derived class whose code first runs a private "loader" method (which loads the collection items), and then returns the base class' value.
Example:
public class MyCollection : ReadOnlyCollection<thing> {
public MyCollection : base( new List<thing>() ) {
}
public new int Count {
get { Load();
return base.Count; }
private void Load() {
// Go to the data source and populate the collection in here
// if it hasn't already been loaded
}
}
It works fine if I work with the derived class.
The problem is that when I assign the class as a DataSource to a windows form control, it doesn't work correctly. The reason is that the control is working directly with the "IList" properties/methods, and so doesn't use replacement code in the derived class.
The correct technique would be to "override" the properties/methods (instead of "new"), but that doesn't work because the ReadOnlyCollection base class doesn't define them as virtual.
Has anyone else worked around this?
Thanks in advance
Jon
|
|
|
|
|
I have a multilayered DataGrid for users to drill into some data. They see a "+" symbol, a la Excel, to expand the datarow and see the source data (see Windows Forms 2.0 Programming, Sells & Weinhardt, pg 730).
Works fine, but I would like to remove the hyperlink and present the data automagically for them (one click instead of two). Just like OK dialogs to reconfirm what you just told the dang thing to do, it will annoy people.
In other words, just open the child control and show it.
Saludos,
I
|
|
|
|
|
Hello,
I was wondering if any one have tryed to have dynamic totals in a data grid view control, The issue I have is that the data would be constantly chaning, refiltering based on what the user selects, and if you have, could you give me some hints as to how to go about it. My other idea would be to make the totals out side of the data grid view, but I am unsure of getting summed columns, and specific cell values... any help, ideas or suggestions would be great.
J
|
|
|
|
|
You can add a calculated column to the datatable that will reflect changes when user changes some values. Here is a website explaining how to achieve it. It also provides some other useful information you might need.
Column Expressions, DataRelations, and Computations[^]
|
|
|
|
|
|
how do i calculate subitems[4] * subitems[5] + all item in listview
I tryade:
Int value = 0;
foreach (ListViewItem lvi in listView3.Items)
{
int.Parse(lvi.subtitems[4].ToString())*int.Parse(lvi.subtitems[5].ToString())
}
label10.Text = value.ToString();
and i´m so wrong..!
do u have some suggests??
|
|
|
|
|
This will not work definitely as value never changes and it is equal to zero all the time. Also, you are iterating over the items and calculating the same product. Instead you should sum them. You say that you need to calculate subitems[4] * subitems[5] but subitems of which items?
|
|
|
|
|
calculate subitems[4] * subitems[5] + (next subitem[4] * subitem[5]
for each subitems[4]*[5]
like this:
columnheader1,columnheader2,columnheader3,columnheader4,columnheader5,columnheader6,
........................................................................................3,5........... 100
.........................................................................................3,5.......... 100
the awnser should be: 700
tnx
|
|
|
|
|
I think you are attempting to do something like...
int result = 0;
foreach (lvi item in items)
result += item.subitem[4] * item.subitem[5];
is this what you are attempting to do? I am really confused by how you get 700 from that example. Just ignore in your next post the fact that the numbers are subitems, and pretend like they are already integers so your problem becomes a bit more clear to the rest of us.
-Jeff
|
|
|
|
|
subitem[4] is price/sides and subitem[5] are how many sides
I wanna se the earned money..3,5*100 + 3,5*100 = 700
how do i pass the result to a label.text
|
|
|
|
|
andredani wrote: how do i pass the result to a label.text
Make a string out of the result and assign it to the Text property:
label.Text = result.ToString();
---
single minded; short sighted; long gone;
|
|
|
|
|
Skippums has the answer and to put it to a label.
Label1.Text = result.ToString();
|
|
|
|
|
do i miss something..? i don´t get it?
foreach (ListViewItem item in listview3.items)
{
result += item.subitem[4] * item.subitem[5];
}
Label12.Text = result.ToString();
is this right??
|
|
|
|
|
That will iterate through all the ListViewItems in listview3's items collection.
With each item it will multiple the 4th subitem with the 5th subitem and add that to the result variable. Once the loop has completed, you are assigning that result variable to the Text property of the Label control.
So let's assume this ( using periods for decimal <US Standard> ):
listview3 contains:
row1: blah, blah, blah, blah, 3.5, 100
row2: blah, blah, blah, blah, 2.5, 100
result = 0
First Iteration of loop: 3.5 * 100 = 350 : result = result + 350, so result is now 350
Second Iteration of loop: 2.5 * 100 = 250 : result = result + 350, so result is now 600
Hope that helps explain it.
|
|
|
|
|
You excplains pretty nice Chris =)
int result = 0;
foreach (ListViewItem lvi in listView3.Items)
{
result += (lvi.SubItems[4].ToString()) * (lvi.SubItems[5].ToString());
}
label12.Text = result.ToString();
it says: Error1Operator '*' cannot be applied to operands of type 'string' and 'string'
can´t i use * in that order?
What do should i do??
-- modified at 19:56 Friday 7th September, 2007
|
|
|
|
|
result += (float)(lvi.SubItems[4].Text) * (float)(lvi.SubItems[5].Text);
And also note that result should now be a float, not an int. I didn't even consider that you were using "," as the decimal separator. I am so used to using ".", that I didn't even consider the alternative. Sorry for the confusion.
-Jeff
|
|
|
|
|
i need to get a cell value from each of the selected datagrid rows. i will then put these values in a t-sql delete from statement. i can't seem to find any clear direction on how to loop through a selected set in a datagrid and then get a particular cell value. any re-direction, or comments would be greatly appreciated.
look out, noob wreck'n havoc
|
|
|
|
|
I believe it's a case of doing something like
foreach(DataGridRow row in grid.Rows)
{
string field = row["columnName"].ToString();
string orThisWay = row[0].ToString();
}
You can cast to string, if it's a string, or use the 'as' operator ( better ), but tostring will always give you some sort of string.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I can't use DataGridRow due to the protection level.
I did try this though, which works for a single selected row (now to iterate this through all the selected rows???):
int delRow = (int)dataGrid.CurrentCell.Value;
_connStr = this.getDBConnection("net");
SqlConnection conn = new SqlConnection(_connStr);
string sql = "delete from gisLinkedDocument where LinkKey in (@delRow)";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter parm = cmd.Parameters.Add("@delRow", SqlDbType.Int);
parm.Value = delRow;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{
MessageBox.Show("The link was NOT deleted");
}
finally
{
if (conn.State != ConnectionState.Closed)
conn.Close();
}
look out, noob wreck'n havoc
|
|
|
|
|
I belive you can do something according to:
List<int> selectedRowIndexes = new List<int>();
foreach(DataGridViewRow row in dataGrid.SelectedRows)
{
selectedRowIndexes.Add(row.Index);
}
... code for deleting the indexes ...
Happy coding!
-Larantz-
-- modified at 18:00 Friday 7th September, 2007
Fixed missing <> for the generic list.
|
|
|
|