|
|
Friends, good morning everyone.
I am needing to define the columns and their characteristics to a temporary DataTable, and not let it generates the columns, the data are inserting correctly, I have my grid:
<asp:GridView ID="GridResumoTotal" runat="server" Height="2px"
Width="100%" AutoGenerateColumns="true" >
</asp:GridView>
I wanted to set my grid with the fields and formatting without using AutoGenerateColumns
I greatly appreciate the help!
I'm doing this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dtb = CriaDataTable();
Session["mDatatable"] = dtb;
GridResumoTotal.DataSource = ((DataTable)Session["mDatatable"]).DefaultView;
GridResumoTotal.DataBind();
}
private DataTable CriaDataTable()
{
DataTable mDataTable = new DataTable();
DataColumn mDataColumn;
mDataColumn = new DataColumn();
mDataColumn.DataType = Type.GetType("System.String");
mDataColumn.ColumnName = "MODALIDADE";
mDataTable.Columns.Add(mDataColumn);
mDataColumn = new DataColumn();
mDataColumn.DataType = Type.GetType("System.String");
mDataColumn.ColumnName = "QTD_OBJ_16";
mDataTable.Columns.Add(mDataColumn);
mDataColumn = new DataColumn();
mDataColumn.DataType = Type.GetType("System.String");
mDataColumn.ColumnName = "QTD_OBJ_17";
mDataTable.Columns.Add(mDataColumn);
return mDataTable;
}
private void incluirNoDataTable(string modalidade, string qtd_obj16, string qtd_obj_17, DataTable mTable)
{
DataRow linha;
linha = mTable.NewRow();
linha["MODALIDADE"] = modalidade;
linha["QTD_OBJ_16"] = qtd_obj16;
linha["QTD_OBJ_17"] = qtd_obj_17;
mTable.Rows.Add(linha);
}
GridResumoTotal.Columns.Clear();
incluirNoDataTable("TOTAL GERAL DIA : ", footer.Cells[16].Text,footer.Cells[17].Text, (DataTable)Session["mDatatable"]);
GridResumoTotal.DataSource = ((DataTable)Session["mDatatable"]).DefaultView;
GridResumoTotal.DataBind();
|
|
|
|
|
Youdo notactually ask a question, just state what you are doing, What do you mean by
Member 10633779 wrote: and not let it generates the columns
You need to tell us what the problem is more clearly.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good day all,
I am a beginner in programing and I can't get the below code to function properly.
when I use the two Response.write(role)statements, the code executes fine but when I comment them and use Response.write("users page") and Response.write("admins Page"), I always get the response: "admins page".
can someone please help and explain why this is happening?
myCon.Open();
SqlCommand com3 = new SqlCommand("checkRole", myCon);
com3.CommandType = CommandType.StoredProcedure;
com3.Parameters.AddWithValue("@uName", TBoxUName.Text);
String role = com3.ExecuteScalar().ToString();
myCon.Close();
if (role == "user")
{
Response.Write("Users Page");
}
else
{
Response.Write("Admins Page");
}
|
|
|
|
|
When you use Response.Write(role) , what value is written to the response?
The equality operator for strings is case-sensitive. If the role contains "User" , it won't be considered equal to "user" . You'd need to use the string.Equals method passing an appropriate StringComparison option instead:
if (string.Equals(role, "user", StringComparison.OrdinalIgnoreCase))
{
Response.Write("Users Page");
}
else
{
Response.WRite("Admins Page");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The value I get when I use response.write(role) is lower case e.g. user or admin which is exactly the same as the string literals I am using in the if statements
|
|
|
|
|
Check the output of your stored procedure. It may not be returning what you think.
|
|
|
|
|
All you need to do is put a breakpoint and step through the code. You'll be able to see exactly what is happening. As pointed out, it's likely a case sensitive issue.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
1. Smells like homework. We will not do your (home)work for you.
2. Read the guidelines about posting a question. The subject "plz" is not really helpful
3. Open up google and read up about generic methods. Take your class notes as well. Then try to come up with a solution. If you get stuck, post the code you tried here and ask a specific question.
modified 28-Feb-14 3:36am.
|
|
|
|
|
That's your homework, isn't it? Shame on you!
|
|
|
|
|
|
Can you define what an element means in this case.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Probably not. 
|
|
|
|
|
Excellent, I'm delighted that you have the chance to display your abilities in developing an application. Now is your opportunity to prove that you were really listening in your lessons, and that you have the ability to go off and do some research and abstract thinking on your own.
Fortunately for you, the question provides several clues as to what you need to be looking at. The first thing is that you need a generic method. Now, this could mean a couple of things so I'll go over them both with you. The first thing it could mean is that it is a method that has a generic parameter, while the second thing is that it might accept a generic type as an input. I know that seems complicated but it makes more sense when you look at the next requirement that it will accept a list of elements.
Right, your method accepts a generic list. We still haven't decided whether it's a generic parameter or a generic type, but you have some clues that you need a generic list. I suggest you look up List<T> to get an understanding of what I'm talking about (now, you could be really clever and allow the method to accept any type that implements IList<T> but I think you should limit yourself to the basics for the moment). So, you have a List of type T - this is a generic. Now, you could either create your method using something like void MyMethod<TList, TType>(TList items) or void MyMethod<T>(List<T> items). It's up to you, but you need to decide now whether or not you need to apply generic constraints to T. At this point, you really need to decide what elements actually means - does it mean you limit to classes, or do you allow primitive types as well.
The iteration part is trivial - you really should be able to accomplish that on your own.
|
|
|
|
|
You're like a breath of fresh air in this place +5
Everyone dies - but not everyone lives
|
|
|
|
|
This doesn't require generics at all.
|
|
|
|
|
I got the treeview displaying my xml right,
now I just need to get the listview working.
here is the code for the treeview
private void button1_Click(object sender, EventArgs e)
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(path + @"\Graw Mission Script\mission.xml");
xDoc.SelectSingleNode("mission_script");
treeView1.Nodes.Clear();
treeView1.Nodes.Add(new TreeNode(xDoc.DocumentElement.Name));
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];
AddNode(xDoc.DocumentElement, tNode);
treeView1.CollapseAll();
}
catch (XmlException xmlEx) { MessageBox.Show(xmlEx.Message); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;
int i;
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (i = 0; i <= nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
inTreeNode.Nodes.Add(new TreeNode(xNode.Name));
tNode = inTreeNode.Nodes[i];
AddNode(xNode, tNode);
}
}
else
{
listView1.Items.Add(inXmlNode.OuterXml);
}
}
I really need help populating to listview
modified 28-Feb-14 17:38pm.
|
|
|
|
|
Massive code-dumps are not the right way to get help here.
What is not working right now: is loading the TreeView not working; or, is it creating some TreeNodes, but what's created is not what you want ?
Where do any specific errors occur, and what are the error messages ?
You say you want to click on a TreeNode, and have it somehow show up in the ListView: but, I see no evidence you've defined an 'AfterSelect EventHandler for the TreeView that would update the ListView.
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
daddy356 wrote: help populating to listview If your goal is to populate the ListView with items linked to only TreeNodes that have no child nodes, then your code looks fine to me. Is there something wrong with the ListView's contents after the tree is constructed ?
How about your goal of synchronizing the ListView with the TreeView ? "click on a node in treeview and display and edit data in listview" can be interpreted a variety of ways, and I'm trying to imagine how that fits in with the state of the ListView after the TreeView is constructed, as shown in your code.
One technique I've used a lot in synchronizing TreeViews and ListViews is to create "symmetric" Dictionaries, like this:
private readonly Dictionary<ListViewItem, TreeNode> dctLvItmToTNode = new Dictionary<ListViewItem, TreeNode>();
private readonly Dictionary<TreeNode, ListViewItem> dctTNodeToLvItm = new Dictionary<TreeNode, ListViewItem>();
private TreeNode currentNode;
private ListViewItem currentLVItem;
private bool dontRecurse;
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (dontRecurse) return;
if (dctTNodeToLvItm.TryGetValue(e.Node, out currentLVItem))
{
dontRecurse = true;
currentLVItem.Selected = true;
dontRecurse = false;
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (dontRecurse || listView1.SelectedItems.Count == 0) return;
if (dctLvItmToTNode.TryGetValue(listView1.SelectedItems[0], out currentNode))
{
dontRecurse = true;
treeView1.SelectedNode = currentNode;
dontRecurse = false;
}
} Use of Dictionaries provide fast look-up. Hope this is useful.
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
Very strange: I just composed a reply to another post from the OP, "daddy356," dated March 3, which had revised code and some questions, and then got a "no permission" error to post that reply, and now, the post I replied to has disappeared !
Well, in case it might be useful: here it is:
Your first code example showed the ListView only being populated with 'inXmlNode items that had no child nodes.
The second code example shows the ListView being populated when the current selected TreeNode is not a root node (Parent == null), and where the selected node has more than 1 child node, in which case, you want to populate the ListView with all first-level child nodes of the SelectedNode.
I wonder if you didn't mean to test for:
tv.SelectedNode.Nodes.Count > 0 If that's the case then you could exclude the nodes you don't want to represent in the ListView by:
if (tv.SelectedNode.Parent == null || tv.SelectedNode.GetNodeCount(false) == 0) return; Note that the 'false argument to GetNodeCount means it will return the same number as if you executed: SelectedNode.Nodes.Count.
Your code is adding Columns to the ListView, not Items ! Try:
foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
{
listView1.Items.Add(tvNode.Text);
} The secret to using the 'symmetric dictionaries trick I described above relies on making sure that each Node and ListViewItem have "matching" cross-references in the two Dictionaries. In the case that you re-populate the ListView, for cross-selection to work you must re-use the existing ListViewItems, not create new ones.
To make that work, you need to do something like this:
foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
{
listView1.Items.Add(dctTNodeToLvItm[tvNode]);
}
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
modified 8-Mar-14 10:14am.
|
|
|
|
|
 Well Bill,
I tried your code, I just don't think I'm including it right in my code.
I managed to get the node text listed in columns and their values
listed below each node.
Now I need to figure out how to edit the value in list view and then save them, also apply an image list to the tree view with
different images for nodes.
Here is what I have:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace TestXml
{
public partial class test : Form
{
public test()
{
InitializeComponent();
}
private string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
XmlDocument xDoc = new XmlDocument();
List<string> values = new List<string>();
private void test_Load(object sender, EventArgs e)
{
textBox1.Text = path + @"\Graw Mission Script\mission.xml";
}
private void button1_Click(object sender, EventArgs e)
{
xDoc.Load(textBox1.Text);
StreamReader sr = new StreamReader(path + @"\Graw Mission Script\mission.xml");
textBox2.Text = sr.ReadToEnd();
try
{
treeView1.Nodes.Clear();
treeView1.Nodes.Add(xDoc.DocumentElement.Name);
AddNode(xDoc.DocumentElement, treeView1.Nodes[0]);
treeView1.CollapseAll();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
public void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlAttributeCollection atts = inXmlNode.Attributes;
TreeNode tNode = new TreeNode("Attributes");
if (atts.Count != 0)
{
foreach (XmlAttribute att in atts)
{
tNode.Nodes.Add(att.Name).Nodes.Add(att.Value);
}
inTreeNode.Nodes.Add(tNode);
}
foreach (XmlNode xNode in inXmlNode.ChildNodes)
{
switch (xNode.NodeType)
{
case XmlNodeType.Element:
tNode = new TreeNode("<" + xNode.Name + ">");
AddNode(xNode, tNode);
break;
case XmlNodeType.Comment:
tNode = new TreeNode("<!--" + xNode.Value + "-->");
break;
case XmlNodeType.CDATA:
tNode = new TreeNode("#cdata " + xNode.Value);
break;
default:
throw new Exception("Unexpected NodeType: " + xNode.NodeType.ToString());
}
inTreeNode.Nodes.Add(tNode);
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
listView1.Clear();
TreeView tv = (TreeView)sender;
if (tv.SelectedNode.Text != "Attributes")
{
return;
}
if (tv.SelectedNode.Parent == null || tv.SelectedNode.GetNodeCount(false) == 0) return;
{
foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
{
listView1.Columns.Add(tvNode.Text);
values.Add(tvNode.Nodes[0].Text);
}
ListViewItem item = listView1.Items.Add(values[0]);
values.RemoveAt(0);
if (values.Count > 0)
{
item.SubItems.AddRange(values.ToArray());
}
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
any help with that would be greatly appreciated.
modified 9-Mar-14 18:16pm.
|
|
|
|
|
I will take a look at your current code later today (GMT + 07 here). cheers, Bill
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
I really appreciate it cheers
|
|
|
|
|
If you go with the "symmetric dictionary" strategy I suggested, then synchronized updating of edits of the Labels of TreeView Nodes, or ListView Items is easy:
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
currentNode = e.Node;
if (dctTNodeToLvItm.TryGetValue(currentNode, out currentLVItem))
{
currentLVItem.Text = e.Label;
}
}
private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
currentLVItem = listView1.Items[e.Item];
if (dctLvItmToTNode.TryGetValue(currentLVItem, out currentNode))
{
currentNode.Text = e.Label;
}
} More later today, as I have time.
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|