|
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.
|
|
|
|
|
Ups.
I wrote it as generic but I forgot to tick the 'Ignore Html'...
I'll fix it now.
-Larantz-
|
|
|
|
|
How do i login by a streamreader .txt file..?
when:
textbox1.text(username)
textbox2.text(username)
.txt file are build like this
#
username
password
Tnx All!!;) 
|
|
|
|
|
your question is missing a lot of details. File.ReadAllLines ( from memory ) returns a string array from your file, so that's a good way to get out your username and password, is that the bit you're stuck on ? Log on to where ? What do textboxes have to do with it ? Is there a typo in your post, is the second textbox the password ? They are surely not named that ?
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 )
|
|
|
|
|
no that´s just an example..
On a button_click event
string q = textBox1.Text;
string w = textBox2.Text;
string[] lines = System.IO.File.ReadAllLines(".txt");
Int32 index = 0;
while (lines.Length >= index + 10)
{
if ("#" != lines[index].Trim())
{
index++;
continue;
}
String username = lines[index + 0];
String password = lines[index + 1];
index += 1;
if (q = username && w = password)
something like this.. but its wrong, how do i start a search on textbox1.text on row0 and textbox2.text are gonna be below.. or something???
tnx ;);P
-- modified at 12:47 Friday 7th September, 2007
|
|
|
|
|
Hi all,
I have a .h file written in c++ that contains the dfinition for some chip's registers.
how can I use this file in c# to avoid rewriting the same definitions again in C#.
Thank you
|
|
|
|
|
Hi,
AFAIK you can't use header files in C#.
What you can do is define a C# struct and give it the right attributes to make
sure the order is preserved, padding does not occur, etc.
How do you plan on accessing your chip from C#? Wouldn't that require some
native code, hence C/C++ anyway? So why do you need the registers at the C# level??
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|