In my MFC application, im adding CListCtrl in my View class using OnCreate() function. I have 10 columns and 8 rows in that table. I want to include check box in second column .
My code is
int CTrendView::OnCreate(LPCREATESTRUCT l)
{
m_ctLstCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT ,listRect, this, IDC_TRENDLISTCTRL);
m_ctLstCtrl.SetExtendedStyle(m_ctLstCtrl.GetExtendedStyle() | LVS_EX_GRIDLINES| LVS_EX_FULLROWSELECT| LVS_EX_ONECLICKACTIVATE );
m_ctLstCtrl.SetBkColor(RGB(255,255,255));
m_ctLstCtrl.SetTextColor(RGB(0,0,0));
m_ctLstCtrl.SetTextBkColor(RGB(255,255,255));
m_ctLstCtrl.InsertColumn(0,_T(""),LVCFMT_LEFT,10);
m_ctLstCtrl.InsertColumn(1,_T("Visible"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(2,_T("Status"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(3,_T("Color"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(4,_T("Object1"),LVCFMT_RIGHT,100);
m_ctLstCtrl.InsertColumn(5,_T("Object2"),LVCFMT_RIGHT,100);
m_ctLstCtrl.InsertColumn(6,_T("Desc"),LVCFMT_RIGHT,100);
m_ctLstCtrl.InsertColumn(7,_T("Value"),LVCFMT_LEFT,100);
m_ctLstCtrl.InsertColumn(8,_T("Low"),LVCFMT_LEFT,100);
m_ctLstCtrl.InsertColumn(9,_T("High"),LVCFMT_LEFT,100);
}
Im using below function to add green color in third column and fourth column.
void CTrendView::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
*pResult = CDRF_DODEFAULT;
switch(pLVCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
{
if(pLVCD->iSubItem == 2 )
pLVCD->clrTextBk = RGB(0, 255, 0);
else
pLVCD->clrTextBk = RGB(255, 255, 255);
}
for(int i=0;i<8;i++)
{
if(pLVCD->nmcd.dwItemSpec == i && pLVCD->iSubItem == 3)
pLVCD->clrTextBk = PenSelect[i];
}
break;
}
}
For adding dynamic values for other columns im using one Fucntion getting called from OnDraw().
void DrawData(CDC *pDC,int iTagPos,CListCtrl &TagListctrl,CRect rect,int pType,float pScaleLow,float pScaleHigh, int TimeCursorPos,int pFlag,CString stime)
{
int index;
CString sPV, sType;
sType = ".SV";
if (TrendTempSV[TimeCursorPos] != -999999)
{
sPV.Format ("%3.2f",TrendTempSV[TimeCursorPos]);
}
else
sPV.Format ("%s","**.** ");
CString sScaleLow,sScaleHigh,indexno;
sScaleLow.Format ("%4.1f",pScaleLow);
sScaleHigh.Format ("%4.1f", pScaleHigh);
indexno.Format("%d",iTagPos+1);
TagListctrl.SetRedraw( FALSE );
TagListctrl.DeleteItem(iTagPos);
index = TagListctrl.InsertItem(iTagPos,indexno);
TagListctrl.SetItemText(iTagPos,4,"Object");
TagListctrl.SetItemText(iTagPos,5,sName);
TagListctrl.SetItemText(iTagPos,6,sDesc);
TagListctrl.SetItemText(iTagPos,7,sPV);
TagListctrl.SetItemText(iTagPos,8,sScaleLow);
TagListctrl.SetItemText(iTagPos,9,sScaleHigh);
TagListctrl.SetRedraw( TRUE );
}
I want check box under 'Visible' column. FOr that, i include | LVS_EX_CHECKBOXES in SetExtendedStyle.
m_ctLstCtrl.SetExtendedStyle(m_ctLstCtrl.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_GRIDLINES|
LVS_EX_FULLROWSELECT| LVS_EX_ONECLICKACTIVATE );
Im facing below problem by doing this. Checkbox appears in first column with index number. The ListCtrl start to flicker,headers are not visible,only when i click somwhere in listctrl each column header et appears one by one and the sixe of the listctrl also not same as previous. How can i avoid this?
You might want to check out XListCtrl. It features checkbox columns at arbitrary positions as well as text formatting of cell content (color).
Also, you can use CListCtrlExt (or CListViewExt), which are not custom draw !! that is mean you can have OS style intact and you can put on every column, any kind of control, including check box button ...
Related
Using the Calendar component in Extjs 7.0 we noticed that the header cells didn't line up correctly with their columns if the language was set to Dutch:
When checking the source code I found the place where these values are added in the cell html;
In Ext.calendar.header.Base, in the setHeaderText function the following code exists:
var me = this,
D = Ext.Date,
value = me.getValue(),
format = me.getFormat(),
domFormat = me.domFormat,
cells = me.cells,
len = cells.length,
useDates = me.useDates,
cell, i;
if (!value) {
return;
}
value = D.clone(value);
for (i = 0; i < len; ++i) {
cell = cells[i];
if (useDates) {
cell.setAttribute('data-date', D.format(value, domFormat));
}
cell.setAttribute('data-day', value.getDay());
cell.innerHTML = D.format(value, format);
value = D.add(value, D.DAY, 1);
}
The innerHtml is set by formatting the Date(D) object which results in the 3 characters of that day. If you change this to just setting a 4 char value like cell.innerHTML = 'Test' the headers line up just fine:
But for some reason this doesn't work when using the D.format value. If somebody has any idea what causes this, I would love to hear.
I can't seem to test if this also goes wrong in another language cause for some reason my packages can't be loaded in anymore.
You can set(or fix) localization override localization constants.
Calendar use Ext.Date.dayNames and Ext.Date.getShortDayName().
All constants list you can see in localization package.
Fiddle example
This is probably easy but I just cannot get the answer. Here is a simple Array:
I want the information to be distributed from an Input textBox to different dynamic textBox after a click. I am OK with buttons.
var ERLQ1:Array = ["ERLQ1", "N09°02.61 / E100°49.11", "ErawanLq"];
InputText = "ERLQ1";
//I want to display:
Txt1 = "ERLQ1" //Being first part of the array as main reference.
Txt2 = "N09°02.61 / E100°49.11" // Should be: String(ERLQ1[1])
Txt3 = "ErawanLq" // Should be: String(ERLQ1[2])
First time I write in a forum like this. Please forgive if not perfect. Thanks in advance.
Andre
If I understand correctly, an array of objects would work well. Since you have a set number of textfields I assume that you also have a set number of details that you want to display in them. If that is the case, this solution should work fine.
arr:Array = [{_name:"ERLQ1",ans1:"N09°02.61 / E100°49.11",ans2:"ErawanLq"},
{_name:"ERLQ2",ans1:"question 2 answer 1",ans2:"ques2ans1"}];
So, I don't really "get" your application, but if it were some sort of a quiz, you'd have a new array element for each question, and that element has a name, and two answers. Easy to modify it to grab answers from an answer pool. Now to find the element in the array that has ._name == "ERLQ1" you will need to loop through all the elements and return the one that has the ._name property that matches your search. Here is an example function:
private function matchName(arr:Array, term:String):int{
for (var i:int = 0; i < arr.length; i++){
if (arr[i]._name == term){
return i;
}
}
return -1;
}
This function will return the array index number of the matching term. If no match exists, it returns -1. So you could use it like this (pseudocode):
// on submit search{
// find the index number in the array of the element that matches the search term
var ind:int = matchName(arr, searchTerm);
// assign the textfield texts to the corresponding associated values
textBox1:text = arr[ind]._name;
textBox2:text = arr[ind].ans1;
textBox3:text = arr[ind].ans2;
}
I perhaps misunderstood (because of my English), but :
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
var ERLQ1:Array = ["ERLQ1", "N09°02.61 / E100°49.11", "ErawanLq"];
var Txt1 : TextField = new TextField();
Txt1.autoSize=TextFieldAutoSize.CENTER;
Txt1.type = TextFieldType.INPUT;
Txt1.border = true;
var Txt2 : TextField = new TextField();
Txt2.autoSize=TextFieldAutoSize.CENTER;
Txt2.type = TextFieldType.INPUT;
Txt2.border = true;
var Txt3 : TextField = new TextField();
Txt3.autoSize=TextFieldAutoSize.CENTER;
Txt3.type = TextFieldType.INPUT;
Txt3.border = true;
addChild(Txt1);
addChild(Txt2);
addChild(Txt3);
Txt1.x = 20, y =40;
Txt2.x = 180, y =40;
Txt1.x = 300, y =40;
Txt1.text = ERLQ1[0]; // is now : first part of the array as main reference (String(ERLQ1[0]).
Txt2.text = ERLQ1[1]; // is now : String(ERLQ1[1]);
Txt3.text = ERLQ1[2]; // is now : String(ERLQ1[2]);
This will display 3 TextFiels as input text like this :
If I misunderstood your question, please tell me more about what You expect!
Best regards.
Nicolas
All examples I found was C# related, but I'm unfamiliar with it.
My task is to provide some kind of automation for testing. I have installer which first buttons are inside of SysListView32, as I can understand
My target is to select them, choose button by its name and click it
The last part is obvious:
GetWindowText(control, window_name, 256);
if(strcmp.....
{
do smth
}
But when it comes to SysListView32 I can't understand how to extract its object and names in C
Take a look at LVM_GETITEM. The MSDN documentation page is here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb774953(v=vs.85).aspx. The documentation is actually pretty thorough.
A short example that will retrieve the "lParam", the image list index for the icon and the text of an item:
LVITEM lvItem;
TCHAR szBuffer[MAX_PATH + 1] = { 0 };
lvItem.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
lvItem.iItem = iItem;
lvItem.iSubItem = 0;
lvItem.pszText = szBuffer;
lvItem.cchTextMax = MAX_PATH;
if(ListView_GetItem(m_hListView,&lvItem))
{
/* success! the item details are in lvItem */
}
I am trying new things with arrays and having some difficulty. I am trying to create multiple instances of 1 class and putting them into an array.
I am creating the instances like so:
public function creatingitem(e:TimerEvent)
{
amtcreated = Math.ceil(Math.random() * 4);
while (amtcreated >= 1)
{
amtcreated--;
var i:Number = Math.ceil(Math.random() * 3);
switch (i)
{
case 1 :
//Object1
objectnum = 1;
objectwei = 3;
r = new Board(objectnum,objectwei,stagw,stagh);
addChild(r);
fallingitem.push(r);
break;
case 2 :
//Object2
objectnum = 2;
objectwei = 4;
c = new Board(objectnum,objectwei,stagw,stagh);
addChild(c);
fallingitem.push(c);
break;
case 3 :
//Object3
objectnum = 3;
objectwei = 4;
l = new Board(objectnum,objectwei,stagw,stagh);
addChild(l);
fallingitem.push(l);
break;
default :
break;
}
}
}
Once these are created they check if they collide with the main ball:
public function hitcheck(e:Event)
{
for (var v:int = fallingitem.length - 1; v >= 0; v--)
{
if (ball.hitTestObject(fallingitem[v]))
{
trace(fallingitem[v]);
if (fallingitem[v] == r)
{
bonusscore += 100;
fallingitem[v].removeitem();
}
else if (fallingitem[v] == c)
{
bonusscore += 75;
fallingitem[v].removeitem();
}
else if (fallingitem[v] == l)
{
bonusscore += 75;
fallingitem[v].removeitem();
}
trace(bonusscore);
}
}
}
The issue is I am seeing every item getting hit due to the trace function. Not all instances are meeting the if conditions. As an example I could have 2 "r" instances and when I hit both 1 will go through and add to the score and the other will just continue past. The trace directly following the hitTestObject shows me that both are being hit and registered but I am not sure why it does not add score.
Thank you,
You can't really have 2 r instances. When you're creating the instances, if you happen to create 2 rs, the second r = new Board... statement overwrites the reference, and the variable r is referring to the second one. Both objects still exist, but the variable can only refer to one of them, so when you perform the check, you're ignoring the object that was previously set to r but isn't any more.
To fix this, you could turn r, c and l into Arrays and whenever you create an instance, add it to the appropriate array. Then, you would perform the check using (r.indexOf(fallingitem[v]) != -1), which returns true if the object is in the array.
The other way, based on the provided code, would be to check whatever value objectnum is setting in the constructor, since you're setting that value based on whether it's in the r, c or l category. Though, that won't work if the property is private or might be changed.
I have a listview with 3 coloumns. The first two columns has values and the third one is empty yet. I want to know, how can i insert a colored text later into the third column? I don't want to color the full row, only the third column with changing colors.
Thanks in advance!
kampi
You can do this with the CustomDraw handler, ref: MSDN Developing Custom Draw Controls in Visual C++.
Basically it's quite simple (and the MSDN quite long) but it boils down to the following:
add one of these to the usual place:
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
Then add this method to the class.
void CMyListView::OnCustomDraw(NMHDR* nmhdr, LRESULT* result)
{
LPNMLVCUSTOMDRAW vcd = (LPNMLVCUSTOMDRAW)nmhdr;
switch(vcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
{
*result = CDRF_NOTIFYITEMDRAW;
break;
}
case CDDS_ITEMPREPAINT:
{
vcd->clrText = RGB(255,0,255); //change the colour of the second row.
*result = CDRF_NOTIFYSUBITEMDRAW;
break;
}
default:
*result = 0;
break;
}
return;
}
#Richard Harrison has the right idea in using NM_CUSTOMDRAW.
Rather than re-implementing the needed functionality though you should consider using one of the freely available CListView derived types.
Here is a project that I think will meet your needs.