Display Hierarchical Data with UltraWinGrid with some customized grid Appearance settings? - c#

I have objects which looks like this:
public class ComponentProperty
{
public string Property { get; set; }
public object Value { get; set; }
public string DataType { get; set; }
public string PropertyKey { get; set; }
public string Unit { get; set; }
public string DependencyType { get; set; }
public object ListType { get; set; }
public List<ComponentProperty> Properties { get; set; }
}
I have information build over in the following form of BindingList where Output is:
public class ComponentPropertyList: BindingList<ComponentProperty>
{
}
Scenario:
List of Component Properties bind to a Infragistics Ultra WinGrid to generate Master- Detail View and i made following customization in Grid settings:
void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Synchronized;
e.Layout.Bands[0].Override.HeaderAppearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
ultraGrid1.DisplayLayout.Appearance.BackColor = Color.White;
ultraGrid1.DisplayLayout.Appearance.BackColor2 = Color.White;
ultraGrid1.DisplayLayout.Override.ActiveRowAppearance = null;
ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.None;
ultraGrid1.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.None;
ultraGrid1.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.None;
ultraGrid1.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.Default;
ultraGrid1.DisplayLayout.Bands[0].ColHeadersVisible = true;
ultraGrid1.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.NoEdit;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellActivation = Activation.AllowEdit;
//Infosys: Nikita - Added for #1143 - START
ultraGrid1.DisplayLayout.Bands[0].Columns["Unit"].CellActivation = Activation.NoEdit;
//Infosys: Nikita - Added for #1143 - END
ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BorderColor = Color.Black;
ultraGrid1.DisplayLayout.Override.RowAppearance.TextVAlign = VAlign.Middle;
// e.Layout.Bands[0].Columns[1].Width = 90;
ultraGrid1.DisplayLayout.Scrollbars = Scrollbars.Automatic;
ultraGrid1.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
ultraGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
ultraGrid1.DisplayLayout.Bands[0].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[0].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[0].Columns[2].Hidden = true;
ultraGrid1.DisplayLayout.Bands[0].Columns[3].Hidden = true;
//ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.Collevel].Hidden = true;
//ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.ColID].Hidden = true;
//ultraGrid1.DisplayLayout.Bands[0].Columns[Constants.Colparentid].Hidden = true;
ultraGrid1.DisplayLayout.Bands[0].Columns["DependencyType"].Hidden = true;
ultraGrid1.DisplayLayout.Bands[0].Columns["ListType"].Hidden = true;
//ultraGrid1.DisplayLayout.Bands[0].Override.AllowColSizing = AllowColSizing.Synchronized;
ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.Default;
//ultraGrid1.DisplayLayout.Bands[0].Columns[1].TabStop = false;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackColor = Color.White;
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].CellAppearance.BackColor = Color.White;
ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.CellsOnly;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].SupportDataErrorInfo = DefaultableBoolean.True;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].Width = 200;
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].Width = 120;
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].TabIndex = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns["Unit"].Width = 60;
for (int rowCount = 0; rowCount < ultraGrid1.Rows.Count; rowCount++)
{
UltraGridRow row = ultraGrid1.Rows[rowCount];
if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value)))
{
row.Cells[1].Appearance.BackColor = Color.White;
}
}
ultraGrid1.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
ultraGrid1.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Solid;
ultraGrid1.DisplayLayout.Override.GroupByRowSpacingAfter = 0;
ultraGrid1.DisplayLayout.Override.GroupByRowSpacingBefore = 0;
ultraGrid1.DisplayLayout.Override.HeaderPlacement = HeaderPlacement.OncePerGroupedRowIsland;
if (ultraGrid1.DisplayLayout.Bands.Count > 1)
{
ultraGrid1.DisplayLayout.Bands[1].ColHeadersVisible = false;
ultraGrid1.DisplayLayout.Bands[1].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[1].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[1].Columns[0].CellActivation = Activation.NoEdit;
ultraGrid1.DisplayLayout.Bands[1].Columns[4].CellActivation = Activation.NoEdit;
ultraGrid1.DisplayLayout.Bands[1].Columns[2].Hidden = true;
ultraGrid1.DisplayLayout.Bands[1].Columns[3].Hidden = true;
ultraGrid1.DisplayLayout.Bands[1].Columns["DependencyType"].Hidden = true;
ultraGrid1.DisplayLayout.Bands[1].Columns["ListType"].Hidden = true;
ultraGrid1.DisplayLayout.Bands[1].Columns[0].Width = 120;
//ultraGrid1.DisplayLayout.Bands[1].Columns[0].TabStop = false;
ultraGrid1.DisplayLayout.Bands[1].Columns["Value"].Width = 180;
ultraGrid1.DisplayLayout.Bands[1].Columns["Value"].TabIndex = 0;
ultraGrid1.DisplayLayout.Bands[1].Columns["Unit"].Width = 60;
//ultraGrid1.DisplayLayout.Bands[1].Columns[Constants.ColUnit].TabStop = false;
ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
if (e.Layout.Bands[1].Columns.Exists(" ") == true)
{
ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Width = 0;
}
if (e.Layout.Bands[1].Columns.Exists(" ") == false)
{
ultraGrid1.DisplayLayout.Bands[1].Columns.Add(" ");
ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Header.VisiblePosition = 0;
ultraGrid1.DisplayLayout.Bands[1].Columns[" "].Width = 0;
}
if (ultraGrid1.DisplayLayout.Bands.Count > 2)
{
ultraGrid1.DisplayLayout.Bands[2].ColHeadersVisible = false;
ultraGrid1.DisplayLayout.Bands[2].Columns[2].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[2].Columns[3].AutoSizeMode = ColumnAutoSizeMode.None;
ultraGrid1.DisplayLayout.Bands[2].Columns[0].CellActivation = Activation.NoEdit;
ultraGrid1.DisplayLayout.Bands[2].Columns[4].CellActivation = Activation.NoEdit;
//ultraGrid1.DisplayLayout.Bands[2].Override.AllowColSizing = AllowColSizing.None;
ultraGrid1.DisplayLayout.Bands[2].Columns[2].Hidden = true;
ultraGrid1.DisplayLayout.Bands[2].Columns[3].Hidden = true;
ultraGrid1.DisplayLayout.Bands[2].Columns["DependencyType"].Hidden = true;
ultraGrid1.DisplayLayout.Bands[2].Columns["ListType"].Hidden = true;
ultraGrid1.DisplayLayout.Bands[2].Columns[0].Width = 200;
ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].Width = 120;
ultraGrid1.DisplayLayout.Bands[2].Columns["Unit"].Width = 60;
ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
//ultraGrid1.DisplayLayout.Bands[2].Columns[0].TabStop = false;
ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].TabIndex = 0;
//ultraGrid1.DisplayLayout.Bands[2].Columns[Constants.ColUnit].TabStop = false;
ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
ultraGrid1.DisplayLayout.Bands[2].Columns["Value"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.
if (e.Layout.Bands[2].Columns.Exists(" ") == true)
{
ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Width = 0;
}
if (e.Layout.Bands[2].Columns.Exists(" ") == false)
{
ultraGrid1.DisplayLayout.Bands[2].Columns.Add(" ");
ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Header.VisiblePosition = 0;
ultraGrid1.DisplayLayout.Bands[2].Columns[" "].Width = 0;
}
}
}
e.Layout.Bands[0].Override.CellAppearance.BorderAlpha = Alpha.Transparent;
e.Layout.Bands[0].Override.SelectedCellAppearance.ForeColor = Color.Black;
e.Layout.Bands[0].Override.RowAppearance.BorderAlpha = Alpha.Transparent;
e.Layout.Bands[0].Override.CellAppearance.BackColorAlpha = Alpha.Transparent;
e.Layout.Bands[0].Columns[0].CellActivation = Activation.NoEdit;
e.Layout.Bands[0].Columns[1].CellActivation = Activation.NoEdit;
e.Layout.Bands[0].Columns[2].CellActivation = Activation.NoEdit;
ultraGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
ultraGrid1.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
ultraGrid1.DisplayLayout.Appearance.BackColor = Color.White;
//ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.None;
//ultraGrid1.DisplayLayout.Override.AllowRowLayoutColMoving = GridBagLayoutAllowMoving.None;
ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;
ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextCell;
if (e.Layout.Bands[0].Columns.Exists(" ") == true)
{
ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Width = 0;
//ultraGrid1.DisplayLayout.Bands[0].Columns[" "].ColSpan = 3;
}
if (e.Layout.Bands[0].Columns.Exists(" ") == false)
{
ultraGrid1.DisplayLayout.Bands[0].Columns.Add(" ").DataType = typeof(bool);
ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Header.VisiblePosition = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Width = 0;
// ultraGrid1.DisplayLayout.Bands[0].Columns[" "].ColSpan = 3;
ultraGrid1.DisplayLayout.Bands[0].Columns[" "].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
UltraGridColumn checkBox = ultraGrid1.DisplayLayout.Bands[0].Columns[" "];
}
foreach (UltraGridBand band in ultraGrid1.DisplayLayout.Bands)
{
band.HeaderVisible = false;
}
}
componentProperties collection may have N Level depending on values.
CompoentProperty 1
--------> SubProperty1
---------------->SubSubProperty1
---------------->SubSubProperty1
CompoentProperty 2
--------> SubProperty2
---------------->SubSubProperty2
---------------->SubSubProperty2
---------------------->SubSubProperty3
---------------------->SubSubProperty3
--------------------------->SubSubProperty NN
Problem:
Layout is not correct, there are lots of Banding after assigning DataSource to grid as ComponentProperties Class and Specified Column Size does not take any effect on it.
Previously, i was using datatable as datasource that need to replace with object data source. Is there any settings require to work with object datasources.

I got the some solution from Infragistics fourm, that some what solve the layout problem. As i inspected when i use IList then these settings work correct after setting the MaxBandDepth Property at the form load event.
// Load only upto two descendant bands. So even if the data source has more than 3 level
// deep hierarchy, the UltraGrid will only make use of first two levels and ignore the
// levels deeper than that.
this.ultraGrid1.DisplayLayout.MaxBandDepth = 3;
The problem that was occured was similar as asked in below thread:
First Column of Wingrid Extending too large when datasource is IList
By default, the grid synchronizes the column widths of every band. So
in a case like this where you have a recursive data source, there
are essentially an infinite number of bands and for each band the grid
indents a little bit. This means that the first column gets very big
in order to accommodate the indentation all the way down the
hierarchy. The grid limits you to 100 bands of depth by default,
but that still means 100 level of indentation.
So there are a number of ways you can handle this.
Set MaxBandDepth on the grid to a smaller value. I recommend a value
of between 5 and 8. This will give you pretty good performance on a
decent machine and most users probably won't drill down more than 5
levels, anyway. You could set AllowColSizing to Free. This will stop
the grid from synchronizing the column widths and allow each band's
columns to be sized independently.
References:
MaxBandDepth Changing After Datasource Set
MaxBandDepth is not being used when the datasource is set
Ultragrid Hierarchical DataSource with Multiple Level Paths
UltraGrid hierarchy

Related

How can I give separate events to buttons in datagridview?

dgvaciklamaBtn.Name = "Açıklama";
dgvaciklamaBtn.HeaderText = "Açıklama";
dgvkartvizitBtn.HeaderText = "Kartvizit";
dgvaciklamaBtn.Name = "Oku";
dgvaciklamaBtn.Text = "Oku";
dgvkartvizitBtn.Text = "Görüntüle";
dgvaciklamaBtn.UseColumnTextForButtonValue = true;
dgvkartvizitBtn.UseColumnTextForButtonValue = true;
dgvaciklamaBtn.DefaultCellStyle.BackColor = Color.Red;
dgvkartvizitBtn.DefaultCellStyle.BackColor = Color.Red;
dgvaciklamaBtn.DefaultCellStyle.SelectionBackColor = Color.White;
dgvkartvizitBtn.DefaultCellStyle.SelectionBackColor = Color.White;
dgvaciklamaBtn.Width = 70;
dgvkartvizitBtn.Width = 70;
firmalardtgview.DataSource = firmalartablo;
firmalardtgview.Columns[0].Width = 30;
firmalardtgview.Columns.Add(dgvaciklamaBtn);
firmalardtgview.Columns.Add(dgvkartvizitBtn);
firmalardtgview.Refresh();
private void firmalardtgview_CellContentClick(object sender, DataGridViewCellEventArgs e){
var senderGrid = (DataGridView)sender;
if (e.ColumnIndex == firmalardtgview.Columns["Açıklama"].Index)
{
string firmaid = firmalardtgview.CurrentRow.Cells["ID"].Value.ToString();
int index = firmaidler.IndexOf(firmaid);
MessageBox.Show(aciklamalar[index].ToString(), "Açıklama");
}
}
I want to make separate codes for read and explanation. Should I create separate events? Can it be solved with an if query? i am getting error like this
I solved the problem by taking the index number of the column and comparing it with the index number of the selected column.
It would be better if there is another shortcut. This is how it works.
string kartismi="";
if (e.ColumnIndex == 0)
{
string firmaid = firmalardtgview.CurrentRow.Cells["ID"].Value.ToString();
int index = firmaidler.IndexOf(firmaid);
MessageBox.Show(aciklamalar[index].ToString(), "Açıklama");
}
else if (e.ColumnIndex == 1)
{
string firmaid = firmalardtgview.CurrentRow.Cells["ID"].Value.ToString();
int index = firmaidler.IndexOf(firmaid);
SqlBaglanti.baglanti.Open();
SqlCommand kartvizitisimi = new SqlCommand("SELECT kartvizit_ismi FROM kartvizitler WHERE kartvizit_id=#kid", SqlBaglanti.baglanti);
kartvizitisimi.Parameters.AddWithValue("#kid", kartvizitIDler[index]);
SqlDataReader dr = kartvizitisimi.ExecuteReader();
if(dr.Read())
{
kartismi = dr["kartvizit_ismi"].ToString();
}
SqlBaglanti.baglanti.Close();
Process.Start(Path.Combine(Application.StartupPath,"Kartvizitler",kartismi));
}

C# Create Tracks Parents which Depend on Children

I'm trying to create tracks of Parent that have more than a child and put theme in dynamic ListBox
i have this ParentActivity table"
tblParentActivity
and I want to make tracks depend on ParentActivity table to be in ListBox like this:
Tracks in ListBox
the code so far:
private void TrackingActivity(long ParentActivityID)
{
DataTable dtActiveChild = objA.SelectActivityChild(ParentActivityID);
ListBox lstBox = new ListBox();
lstBox.ID = "lstTrack" + ParentActivityID.ToString();
lstBox.Width = 200;
pnlTrack.Controls.Add(lstBox);
for (int i = 0; i < dtActiveChild.Rows.Count; i++)
{
long ActivityChildID = Convert.ToInt64(dtActiveChild.Rows[i]["ActivityID"].ToString());
string ActivityChildName = dtActiveChild.Rows[i]["ActivityName"].ToString();
lstBox.Items.Add(new ListItem (ActivityChildName.ToString(),ActivityChildID.ToString()));
DataTable dtBrotherActivity = objA.selectBrotherActivity(ActivityChildID);
if (dtBrotherActivity.Rows.Count > 0)
{
TrackingActivity(ActivityChildID);
}
}
}
for example ParentActivityID=1;
selectBrotherActivity is query to get another child of it parent
it gave me distribution like this:
|1|2 3|4 5|7|9|10|7|9|10|6|8|9|10|
which || means ListBox
Ok thanks to everyone I found it:
protected void btnCreateTrack_Click(object sender, EventArgs e)
{
ListBox lstBoxParent = new ListBox();
lstBoxParent.ID = "lstTrack1";
lstBoxParent.Width = 200;
lstBoxParent.Height = 200;
pnlTrack.Controls.Add(lstBoxParent);
TrackingActivity(1, lstBoxParent );
}
private void TrackingActivity(long ParentActivityID, ListBox lstBoxParent)
{
chk:
DataTable dtActiveChild = objWFAI.SelectActivityChild(ParentActivityID);
string ActivityName = objWFA.CurrentActivityName(ParentActivityID);
lstBoxParent.Items.Add(new ListItem(ActivityName, ParentActivityID.ToString()));
for (int i = dtActiveChild .Rows.Count - 1; i >= 0; i--)
{
long ActivityChildID = Convert.ToInt64(dtActiveChild .Rows[i][" ActivityID"].ToString());
if (i != 0)
{
ListBox lstBoxChild = new ListBox();
lstBoxChild.ID = "lstTrack" + ActivityChildID.ToString();
lstBoxChild.Width = 200;
lstBoxChild.Height = 200;
pnlTrack.Controls.Add(lstBoxChild);
for (int p = 0; p < lstBoxParent.Items.Count; p++)
{
lstBoxChild.Items.Add(new ListItem(lstBoxParent.Items[p].Text, lstBoxParent.Items[p].Value));
}
TrackingActivity(ActivityChildID, lstBoxChild);
}
else
{
ParentActivityID = ActivityChildID ;
goto chk;
}
}

how to create multiple column tree view with image

i have a problem. i am using the BrightIdeasSoftware.TreeListView to create treeview in my windows form and i also take the reference of How to create a MultiColumn treeview like this in C# Winforms app but i am not success to create this. Can you please tell me what i am doing mistake to create the treeview. The complete description is below.
i want to add the dynamic collapsible Panel and into this want to add tree in this.
The data will display into the panel according the collapsible panel header id .
i have a parent id and that can have multiple child.
Status Column will display one image
below is my code that i am using to create the treeview
class Node
{
public string Name { get; private set; }
public string Column1 { get; private set; }
public string Column2 { get; private set; }
public List<Node> Children { get; private set; }
public Node(string name, string col1, string col2)
{
this.Name = name;
this.Column1 = col1;
this.Column2 = col2;
this.Children = new List<Node>();
}
}
private void InitializeFristTabValue()
{
if (_UserDAC == null)
_UserDAC = new UserDAC();
try
{
DataTable dtUserGroup = _UserDAC.GetAllSECGROUPS(appDirectory, this.FindForm().Name, "InitializeFristTabValue()").Tables[0];
CommonDataGridBind cc = new CommonDataGridBind();
cc.GridviewGrouping(dtUserGroup, kryptonOutlookGridUserGroup, true, "GROUPID");
DataTable SEC_Info = _UserDAC.GetSECAPPINFO(appDirectory, this.FindForm().Name, "InitializeFristTabValue()").Tables[0];
int Location = 0;
foreach (DataRow dtrow in SEC_Info.Rows)
{
int APPID;
int.TryParse(dtrow["APPID"].ToString(), out APPID);
collapsiblePanelobj = new CollapsiblePanel();
if (Location == 0)
{
collapsiblePanelobj.Collapse = false;
//collapsiblePanelobj.Dock = System.Windows.Forms.DockStyle.Fill;
this.collapsiblePanelobj.Size = new System.Drawing.Size(1000, 150);
//DataTable SEC_InfoTreeView = _UserDAC.GetAPPITEMSbyAPPID(APPID, appDirectory, this.FindForm().Name, "InitializeFristTabValue()").Tables[0];
// ADDNode(APPID);
treeListView1.Dock = System.Windows.Forms.DockStyle.Fill;
//_panelBox.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
//_panelBox.Controls.Add(treeListView1);
//collapsiblePanelobj.Controls.Add(_panelBox);
collapsiblePanelobj.Controls.Add(treeListView1);
}
else
collapsiblePanelobj.Collapse = true;
Location = Location + 30;
collapsiblePanelobj.Name = dtrow["APPNAME"].ToString() + dtrow["APPID"].ToString();
collapsiblePanelobj.HeaderText = "PROGRAM: " + dtrow["APPNAME"].ToString();
collapsiblePanelobj.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
collapsiblePanelobj.BackColor = System.Drawing.Color.Transparent;
collapsiblePanelobj.HeaderCornersRadius = 5;
collapsiblePanelobj.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
collapsiblePanelobj.HeaderImage = null;
collapsiblePanelobj.HeaderTextColor = System.Drawing.Color.Black;
collapsiblePanelobj.Location = new System.Drawing.Point(10, Location);
collapsiblePanelobj.RoundedCorners = true;
//this.collapsiblePanelobj.Dock = System.Windows.Forms.DockStyle.Fill;
this.collapsiblePanelobj.Size = new System.Drawing.Size(1000, 150);
collapsiblePanelobj.UseAnimation = true;
InitializeData(APPID);
FillTree();
AddTree();
panel1.Controls.Add(collapsiblePanelobj);
// GrpBoxUserGroupInfo.Controls.Add(collapsiblePanelobj);
}
}
catch (Exception ex)
{
LogsWrite(ex, appDirectory, this.FindForm().Name, "InitializeFristTabValue()");
}
}
public void ADDNode()
{
AddTree();
InitializeData();
FillTree();
}
private void AddTree()
{
treeListView1 = new BrightIdeasSoftware.TreeListView();
treeListView1.Dock = DockStyle.Fill;
this.Controls.Add(treeListView1);
}
private void InitializeData()
{
UserDAC _UserDAC = new UserDAC();
DataTable SEC_InfoTreeView = _UserDAC.GetAPPITEMSbyAPPID(2, "", this.FindForm().Name, "InitializeFristTabValue()").Tables[0];
data = new List<Node> {};
var parent1 = new Node("User Name ", "State ", "Static Caption ");
for (int i = 0; i < SEC_InfoTreeView.Rows.Count; i++)
{
int PrentID = Convert.ToInt32(SEC_InfoTreeView.Rows[i]["PARENTID"]);
if (PrentID == 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 0)
{
data.Add(parent1);
var parentAdd = new Node(Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"]));
parent1 = parentAdd;
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 2)
{
parent1.Children.Add(new Node(Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
}
}
private void FillTree()
{
// this.treeListView.SmallImageList = imageList1;
// set the delegate that the tree uses to know if a node is expandable
// treeListView1.Margin = new System.Windows.Forms.Padding(2, 1000, 2, 2);
treeListView1.CanExpandGetter = x => (x as Node).Children.Count > 0;
// set the delegate that the tree uses to know the children of a node
treeListView1.ChildrenGetter = x => (x as Node).Children;
// create the tree columns and set the delegates to print the desired object proerty
var nameCol = new BrightIdeasSoftware.OLVColumn("User Name", "Name");
nameCol.AspectGetter = x => (x as Node).Name;
nameCol.Width = treeListView1.Width / 3;
var col1 = new BrightIdeasSoftware.OLVColumn("State", "Column1");
col1.AspectGetter = x => (x as Node).Column1;
col1.Width = treeListView1.Width / 3;
var col2 = new BrightIdeasSoftware.OLVColumn("Static Caption", "Column2");
col2.AspectGetter = x => (x as Node).Column2;
col2.Width = treeListView1.Width / 3;
// add the columns to the tree
treeListView1.Columns.Add(nameCol);
treeListView1.Columns.Add(col1);
treeListView1.Columns.Add(col2);
// set the tree roots
this.treeListView1.Roots = data;
}
Thanks in advance for your help and comments

DataGridView not showing values in runtime created columns

I´m having a really wierd issue. I assign to my DataGridView a list of entities as a DataSource. I create some columns in runtime, and then, for each Row in the DataGridView, I complete the values of that new columns base on some values of some columns of the row.
The code works fine, because I´m displaying that same DataGridView in other forms. But in this new UserControl, it seems that it´s not showing any values on that new columns.
The wierd thing, is that the values are actually there, because when I do the foreach row loop, I have some acumulators int objects that shows the values in a textbox, and the values are correct.
I used a try and catch to see if something was wrong, but everything is fine.
I attached an image of what I´m getting.
Those two highlighted textboxes are the one that acummulates the values of those two columns..
As I said, the same code is working fine in other forms. Just in case, this UserControl is added to a panel in a form.
This is the code I use for the DataGridView:
public void Actualizar_grilla_prestamos()
{
dgv_Prestamos.DataSource = null;
dgv_Prestamos.Columns.Clear();
dgv_Prestamos.DataSource = lista_prestamos;
dgv_Prestamos.RowHeadersVisible = false;
//Agregar columna cuotas restantes
DataGridViewColumn cuotas_restantes = new DataGridViewColumn();
{
cuotas_restantes.HeaderText = "C. Rest.";
cuotas_restantes.Name = "cuotas_restantes";
cuotas_restantes.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
cuotas_restantes.CellTemplate = new DataGridViewTextBoxCell();
cuotas_restantes.ToolTipText = "Cantidad de cuotas restantes por cobrar";
}
dgv_Prestamos.Columns.Add(cuotas_restantes);
//Agregar columna tipo de tasa
DataGridViewColumn tipo_tasa = new DataGridViewColumn();
{
tipo_tasa.HeaderText = "Tipo tasa";
tipo_tasa.Name = "tipo_tasa";
tipo_tasa.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
tipo_tasa.CellTemplate = new DataGridViewTextBoxCell();
}
dgv_Prestamos.Columns.Add(tipo_tasa);
//Agregar columna garantes
DataGridViewColumn garantes = new DataGridViewColumn();
{
garantes.HeaderText = "Garantes";
garantes.Name = "garantes";
garantes.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
garantes.CellTemplate = new DataGridViewTextBoxCell();
}
dgv_Prestamos.Columns.Add(garantes);
dgv_Prestamos.Columns["garantes"].DisplayIndex = dgv_Prestamos.Columns["Cliente1"].Index;
//Agregar columna cuotas mora
DataGridViewColumn cuotas_mora = new DataGridViewColumn();
{
cuotas_mora.HeaderText = "C. Venc.";
cuotas_mora.Name = "cuotas_mora";
cuotas_mora.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
cuotas_mora.CellTemplate = new DataGridViewTextBoxCell();
cuotas_mora.ToolTipText = "Cantidad de cuotas vencidas";
}
dgv_Prestamos.Columns.Add(cuotas_mora);
int cant_total_cuotas_mora = 0;
int total_cuotas_restantes = 0;
foreach (DataGridViewRow r in dgv_Prestamos.Rows)
{
Estado_prestamo estado = (Estado_prestamo)dgv_Prestamos.Rows[r.Index].Cells["Estado_prestamo"].Value;
if (estado.id_estado_prestamo != 3)
{
var lista_cuotas = (System.Data.Objects.DataClasses.EntityCollection<Sistema_financiero.Cuota>)dgv_Prestamos.Rows[r.Index].Cells["Cuota"].Value;
dgv_Prestamos.Rows[r.Index].Cells["cuotas_mora"].Value = lista_cuotas.Where(x => x.pagada != true && x.fecha_vencimiento < DateTime.Now.Date).Count();
if (Convert.ToInt32(dgv_Prestamos.Rows[r.Index].Cells["cuotas_mora"].Value) > 0)
{
dgv_Prestamos.Rows[r.Index].Cells["cuotas_mora"].Style.ForeColor = Color.Red;
}
dgv_Prestamos.Rows[r.Index].Cells["cuotas_restantes"].Value = lista_cuotas.Where(x => x.pagada != true).Count();
}
else
{
dgv_Prestamos.Rows[r.Index].Cells["cuotas_mora"].Value = 0;
dgv_Prestamos.Rows[r.Index].Cells["cuotas_restantes"].Value = 0;
dgv_Prestamos.Rows[r.Index].Cells["cuotas_restantes"].Style.ForeColor = Color.Green;
}
if (Convert.ToBoolean(dgv_Prestamos.Rows[r.Index].Cells["tasa_fija"].Value) == true)
{
dgv_Prestamos.Rows[r.Index].Cells["tipo_tasa"].Value = "FIJA";
}
else
{
dgv_Prestamos.Rows[r.Index].Cells["tipo_tasa"].Value = "VARIABLE";
}
dgv_Prestamos.Rows[r.Index].Cells["garantes"].Value = ((System.Data.Objects.DataClasses.EntityCollection<Sistema_financiero.Cliente>)dgv_Prestamos.Rows[r.Index].Cells["Cliente1"].Value).Count;
cant_total_cuotas_mora = cant_total_cuotas_mora + Convert.ToInt32(dgv_Prestamos.Rows[r.Index].Cells["cuotas_mora"].Value);
total_cuotas_restantes = total_cuotas_restantes + Convert.ToInt32(dgv_Prestamos.Rows[r.Index].Cells["cuotas_restantes"].Value);
}
tbx_Cuotas_adeudadas_vencidas.Text = cant_total_cuotas_mora.ToString();
tbx_Total_cuotas_restantes.Text = total_cuotas_restantes.ToString();
//Agregar columna ver prestamo
DataGridViewImageColumn ver_prestamo = new DataGridViewImageColumn();
{
ver_prestamo.HeaderText = "";
ver_prestamo.Name = "ver_prestamo";
ver_prestamo.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
ver_prestamo.CellTemplate = new DataGridViewImageCell();
ver_prestamo.Image = Properties.Resources.eye_small_grid;
ver_prestamo.ToolTipText = "Ver préstamo";
}
dgv_Prestamos.Columns.Add(ver_prestamo);
dgv_Prestamos.Columns["ver_prestamo"].DisplayIndex = 0;
dgv_Prestamos.Columns["id_prestamo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["num_cuotas"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["cuotas_mora"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["cuotas_restantes"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["importe"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["Moneda"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dgv_Prestamos.Columns["Sistema_amortizacion"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dgv_Prestamos.Columns["cuotas_mora"].DisplayIndex = dgv_Prestamos.Columns["num_cuotas"].Index + 1;
dgv_Prestamos.Columns["cuotas_restantes"].DisplayIndex = dgv_Prestamos.Columns["num_cuotas"].Index + 1;
dgv_Prestamos.Columns["importe"].DisplayIndex = dgv_Prestamos.Columns["garantes"].DisplayIndex;
dgv_Prestamos.Columns["num_cuotas"].DisplayIndex = dgv_Prestamos.Columns["cuotas_restantes"].DisplayIndex;
dgv_Prestamos.Columns["Estado_prestamo"].DisplayIndex = dgv_Prestamos.Columns[dgv_Prestamos.Columns.Count - 1].Index;
dgv_Prestamos.Columns["Moneda"].DisplayIndex = dgv_Prestamos.Columns[dgv_Prestamos.Columns.Count - 2].Index;
dgv_Prestamos.Columns["tipo_tasa"].DisplayIndex = dgv_Prestamos.Columns["tasa_fija"].Index;
List<int> lista_columnas_visibles = new List<int> { dgv_Prestamos.Columns["Estado_prestamo"].Index, dgv_Prestamos.Columns["garantes"].Index, dgv_Prestamos.Columns["importe"].Index, dgv_Prestamos.Columns["Sistema_amortizacion"].Index, dgv_Prestamos.Columns["tipo_tasa"].Index, dgv_Prestamos.Columns["Moneda"].Index, dgv_Prestamos.Columns["id_prestamo"].Index, dgv_Prestamos.Columns["num_cuotas"].Index, dgv_Prestamos.Columns["cuotas_mora"].Index, dgv_Prestamos.Columns["cuotas_restantes"].Index, dgv_Prestamos.Columns["ver_prestamo"].Index };
Mostrar_ocultar_columnas(dgv_Prestamos, lista_columnas_visibles);
dgv_Prestamos.Columns["num_cuotas"].HeaderText = "Cuotas";
dgv_Prestamos.Columns["id_prestamo"].HeaderText = "Nº";
dgv_Prestamos.Columns["tasa_fija"].HeaderText = "Tipo tasa";
dgv_Prestamos.Columns["importe"].HeaderText = "Importe";
dgv_Prestamos.Columns["Estado_prestamo"].HeaderText = "Estado";
dgv_Prestamos.Columns["Sistema_amortizacion"].HeaderText = "Amortización";
dgv_Prestamos.Columns["importe"].DefaultCellStyle.Format = String.Format("$ ##0.##");
if (dgv_Prestamos.Columns["Moneda"].Width > 99)
{
dgv_Prestamos.Columns["Moneda"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
dgv_Prestamos.Columns["Moneda"].Width = 99;
}
}
You can see that the DataGridView has a column with an eye. If you click the eye, you can see that entity in another form. If you change the entity state in that form, it returns a value (borrado) with true if changes has been made, or false if no change has been made.
If changes were detected, then I call the above method again. Magically, it shows all that missing values!
private void dgv_Prestamos_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (e.ColumnIndex == dgv_Prestamos.Columns["ver_prestamo"].Index)
{
frm_Ver_Prestamo ver_prestamo = new frm_Ver_Prestamo();
ver_prestamo.prestamo_seleccionado = (Prestamo)dgv_Prestamos.Rows[e.RowIndex].DataBoundItem;
ver_prestamo.db = db;
ver_prestamo.ShowDialog();
if (ver_prestamo.borrado == true)
{
dgv_Prestamos.DataSource = null;
Cursor.Current = Cursors.WaitCursor;
Actualizar_grilla_prestamos();
Cursor.Current = Cursors.Default;
}
}
}
}
ver_prestamo is the form that shows the entity. I don´t know what make that work, the only difference is that I do a DataSource = null before. But I do that in the method anyways..
Have you tried moving the dgv_Prestamos.DataSource = lista_prestamos; to the bottom of Actualizar_grilla_prestamos.
I think that it is doing the binding when you set the datasource and can't see the columns you have created afterward.
"Construct the grid, set the DataSource, then change the appearances in the DataBindingComplete event." - glace

how to add items to TreeViewAdv in multi-column mode with winforms

I was playing around with this control called TreeViewAdv. I've already added the control and added couple of columns trying to see how it works. but till now when I add items to the control all I get is empty nodes. the example provided with the control is not clear at all and it just gave me headaches when I try to figure out how the data is being added to it. anyway here is what I've done so far and I hope that someone can guide me to the right direction.
TreeModel _model = new TreeModel();
treeViewAdv1.Model = _model;
treeViewAdv1.BeginUpdate();
for (int i = 0; i < 20; i++)
{
Node parentNode = new Node("root" + i);
_model.Nodes.Add(parentNode);
for (int n = 0; n < 2; n++)
{
Node childNode = new MyNode("child" + n);
parentNode.Nodes.Add(childNode);
}
}
treeViewAdv1.EndUpdate();
anyway, all I'm getting is empty nodes and I really can't figure out how to add data to the other columns... any help would be appreciated...
Obviously this questions is old, but I was unable to find any answers to this question, so I figured I would try to save someone some future frustration.
To get multiple columns to display, first change the UseColumns property to true.
Then add desired columms to the Columns collection property.
Next using the NodeControls collection property to create a list of the types of data that will be shown, and how they should be formatted (Checkbox, TextBox, etc). Make sure to set 1) the DataPropertyName (will be used later), 2) the ParentColumn (to show which column in the treeView is supposed to show the data.
Finally, create a new class inheriting from the Node class, and add a public property with the same name as each NodeControl. Then when adding Nodes, use your new class with the correct value.
private class ColumnNode: Node
{
public string NodeControl1=""; // This sould make the DataPropertyName specified in the Node Collection.
public string NodeControl2 = "";
public string NodeControl3 = "";
public ColumnNode(string nodeControl1, string nodeControl2, int nodeControl3)
{
NodeControl1 = nodeControl1;
NodeControl2 = nodeControl2;
NodeControl3 = nodeControl3.ToString();
}
}
Then when adding the
TreeModel _model = new TreeModel();
_treeViewAdv.Model = _model;
_treeViewAdv.BeginUpdate();
for (int i = 0; i < 20; i++)
{
Node parentNode = new ColumnNode("root" + i, "",0);
_model.Nodes.Add(parentNode);
for (int n = 0; n < 2; n++)
{
Node childNode = new ColumnNode("child" + n,"Further Information",1);
parentNode.Nodes.Add(childNode);
}
}
_treeViewAdv.EndUpdate();
For reference, the designer code for the treeViewAdv in this case would look like this:
private Aga.Controls.Tree.TreeViewAdv _treeViewAdv;
private Aga.Controls.Tree.TreeColumn Column1;
private Aga.Controls.Tree.TreeColumn Column2;
private Aga.Controls.Tree.TreeColumn Column3;
private Aga.Controls.Tree.NodeControls.NodeTextBox NodeControl1;
private Aga.Controls.Tree.NodeControls.NodeTextBox NodeControl2;
private Aga.Controls.Tree.NodeControls.NodeTextBox NodeControl3;
private InitializeComponent()
{
// Left out all other initialization, since this was long enough already.
this.treeViewAdvPrint = new Aga.Controls.Tree.TreeViewAdv();
this.Column1 = new Aga.Controls.Tree.TreeColumn();
this.Column2 = new Aga.Controls.Tree.TreeColumn();
this.Column3 = new Aga.Controls.Tree.TreeColumn();
this.NodeControl1 = new Aga.Controls.Tree.NodeControls.NodeTextBox();
this.NodeControl2 = new Aga.Controls.Tree.NodeControls.NodeTextBox();
this.NodeControl3= new Aga.Controls.Tree.NodeControls.NodeTextBox();
//
// _treeViewAdv
//
this._treeViewAdv.BackColor = System.Drawing.SystemColors.Window;
this._treeViewAdv.Columns.Add(this.Column1);
this._treeViewAdv.Columns.Add(this.Column2);
this._treeViewAdv.Columns.Add(this.Column3);
this._treeViewAdv.DefaultToolTipProvider = null;
this._treeViewAdv.DragDropMarkColor = System.Drawing.Color.Black;
this._treeViewAdv.GridLineStyle = ((Aga.Controls.Tree.GridLineStyle)((Aga.Controls.Tree.GridLineStyle.Horizontal | Aga.Controls.Tree.GridLineStyle.Vertical)));
this._treeViewAdv.LineColor = System.Drawing.SystemColors.ControlDark;
this._treeViewAdv.Location = new System.Drawing.Point(12, 12);
this._treeViewAdv.Model = null;
this._treeViewAdv.Name = "_treeViewAdv";
this._treeViewAdv.NodeControls.Add(NodeControl1);
this._treeViewAdv.NodeControls.Add(NodeControl2);
this._treeViewAdv.NodeControls.Add(NodeControl3);
this._treeViewAdv.SelectedNode = null;
this._treeViewAdv.Size = new System.Drawing.Size(443, 356);
this._treeViewAdv.TabIndex = 6;
this._treeViewAdv.Text = "_treeViewAdv";
this._treeViewAdv.UseColumns = true;
//
// Column1
//
this.Column1.Header = "Column 1";
this.Column1.SortOrder = System.Windows.Forms.SortOrder.None;
this.Column1.TooltipText = null;
this.Column1.Width = 290;
//
// Column3
//
this.Column3.Header = "Column 3";
this.Column3.SortOrder = System.Windows.Forms.SortOrder.None;
this.Column3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.Column3.TooltipText = null;
//
// Column2
//
this.Column2.Header = "Column 2";
this.Column2.SortOrder = System.Windows.Forms.SortOrder.None;
this.Column2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.Column2.TooltipText = null;
this.Column2.Width = 91;
//
// NodeControl1
//
this.NodeControl1.DataPropertyName = "NodeControl1";
this.NodeControl1.IncrementalSearchEnabled = true;
this.NodeControl1.LeftMargin = 3;
this.NodeControl1.ParentColumn = this.Column1;
//
// NodeControl2
//
this.NodeControl2.DataPropertyName = "NodeControl2";
this.NodeControl2.IncrementalSearchEnabled = true;
this.NodeControl2.LeftMargin = 3;
this.NodeControl2.ParentColumn = this.Column2;
//
// NodeControl3
//
this.NodeControl3.DataPropertyName = "NodeControl3";
this.NodeControl3.IncrementalSearchEnabled = true;
this.NodeControl3.LeftMargin = 3;
this.NodeControl3.ParentColumn = this.Column3;
}
It seems as though the price of entry for using this fantastic control is hours, and hours, of head scratching frustration.
This is what you need to do:
private void Form1_Load(object sender, EventArgs e)
{
TreeModel _model = new TreeModel();
treeViewAdv1.Model = _model;
treeViewAdv1.BeginUpdate();
for (int i = 0; i < 20; i++)
{
Node parentNode = new Node("root" + i);
_model.Nodes.Add(parentNode);
for (int n = 0; n < 2; n++)
{
Node childNode = new Node("child" + n);
parentNode.Nodes.Add(childNode);
}
}
NodeTextBox ntb = new NodeTextBox();
ntb.DataPropertyName = "Text";
this.treeViewAdv1.NodeControls.Add(ntb);
treeViewAdv1.EndUpdate();
}
Just in case you're still struggling with the issue, or anyone else is having the same trouble: the solution to empty nodes is to assign a view component to tree.
TreeViewAdv uses MVC, and it requires that you assign a view, though this is not obvious from the example project. NodeTextBox class under NodeControls folder in the source of the TreeViewAdv is one of the viewers you can use. You need to add it to your form and connect it to tree control through its DataPropertyName attribute like this:
this._tBox.DataPropertyName = "Text";
where _tBox is the NodeTextBox instance. Needless to say, I've just lost hours figuring this out. Hope it helps someone else.
You need to instantiate your columns first, then attach them to the TreeView. After all add new cells in all columns at same cell index.
Hope to help

Categories