|
I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview.
Any help would be appreciated.
Thanks
John
|
|
|
|
|
For that you need to use RowDataBound event. Try following code.
protected void MyDataGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (condition)
{
(e.Row.FindControl("buttonid") as Button).Enabled = false;
}
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
hi man,
this could be a possible solution but never tested..
In the CellValueChanged event you have to check your specified cell against your condition and than try:
<br />
dataGridView1.Rows[rowIndex].Cells[buttonCell].ReadOnly = true;<br />
or
<br />
dataGridView1.Rows[rowIndex].Cells[buttonCell].Frozen = true;<br />
hope i could help
|
|
|
|
|
Hey - we're looking at trying to implement a T9-based predictive text capability (like on your cell phone/PDA) into our Windows forms application (this is running on a standard Windows/embedded environment, NOT on a smart phone). Has anyone seen or worked with anything like this in the past?
Cheers,
Chris
|
|
|
|
|
For that you need to do following.
1. Maintain one dictionary which will serve as base for auto suggestion.
2. Bind that dictionary with your textbox.
3. Track keypress event of your textbox and suggest world if it is starting
from the character user enters.
That's All.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks for the reply. However, I'm not sure if you're following one of the key points I was trying to accomplish - T9. I'm not working by standard letter entry, but rather by T9 entry (or the newer XT9). In the very least this would involve adding the equivalent T9 values for each word in the dictionary, but it still wouldn't account for word usage/popularity. Obviously there are ways that this can be coded completely from scratch, but I wanted to first see if anyone was doing something similar using an already establish method, API, etc.
Thanks again.
|
|
|
|
|
Yes definitely possible, though probably not entirely in .NET, and don't think there are API beside the standard Win32 API, and you got to code most of the libraries.
You'll need a light and efficient database for the dictionary, an algorithm to retrieve the words fast, an algorithm to account for the most recent used words, adding and removing words from the dictionary.
You'll need some way to hook the keypress, and sending the character or control characters (backspace, etc) to the control.
Did a Palm version for a friend's company for the keyboard, they did the windows mobile version using C++. Though without much capital, the product is currently sort of dead.
http://www.osnews.com/story/15389/Review-TenGO-2.0-and-TenGO-Thumb[^]
|
|
|
|
|
G-Tek wrote: Has anyone seen or worked with anything like this in the past?
Not T9, but been playing with something similar. Kinda started with a Wiktionary-download, gives you a decent dictionary. Once that was in place, started fetching websites to do a statistical analysis.
Read a few sites in a loop (of the correct target-audience) and mark how often a word follows the previous word. Thus resulted in a crash of my machine
Filtered out all noise-words for the analysis, as there's a lot of words that might follow the word "this". The remark on the target-audience would be important because "this" often has a different meaning on the CodeProject-site than in normal conversation.
..and that's when I stopped playing with it, my harddisk isn't that large. You wouldn't need the complete resultset to give decent options as a prediction; only the top 5000 or so. Still, sounds like a lot of work, and the method that I described here is probably one of the less efficient ways to do it.
I are Troll
|
|
|
|
|
I'm trying to do something that should be simple. We have a DRM encripted WMV file, and we need to control the size of the activation window that comes up while the license is being verified. I've seen files that do this, but we haven't been able to find a way. Apparently this is set by Windows Media Player. How do we tell WMP what size window we want?
|
|
|
|
|
tjeffries wrote: We have a DRM encripted WMV file, and we need to control the size of the activation window that comes up while the license is being verified. I've seen files that do this, but we haven't been able to find a way. Apparently this is set by Windows Media Player. How do we tell WMP what size window we want?
You could try using the WinAPI, using FindWindow and SendMessage to set the appropriate size.
I are Troll
|
|
|
|
|
The following code is meant to draw a grid and is a custom control (one that can be dragged from the toolbox)
:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
AutoScroll = true;
}
Point _rowColumn;
Point _widthHeight;
Rectangle[,] _bound;
public void Init(int x, int y, int width, int height)
{
SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
_rowColumn = new Point(x, y);
_bound = new Rectangle[x, y];
_widthHeight = new Point(width, height);
_drawArea = new Bitmap(Width, Height);
LoadTiles();
_loaded = true;
AutoScrollMinSize = new Size(x * width, y * height);
}
void LoadTiles()
{
for (int x = 0; x < _rowColumn.X; x++)
{
for (int y = 0; y < _rowColumn.Y; y++)
{
_bound[x, y] = new Rectangle(x* _widthHeight.X, y*_widthHeight.Y, _widthHeight.X, _widthHeight.Y);
}
}
}
Bitmap _drawArea;
bool _loaded = false;
void DrawGrid()
{
Graphics gfx = Graphics.FromImage(_drawArea);
gfx.Clear(Color.White);
Pen pen = new Pen(Color.Black,1);
foreach (Rectangle r in _bound)
{
gfx.DrawRectangle(pen, r);
}
gfx.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.Clear(Color.White);
Matrix mx = new Matrix(1, 0, 0, 1, AutoScrollPosition.X, AutoScrollPosition.Y);
e.Graphics.Transform = mx;
e.Graphics.PageUnit = GraphicsUnit.Pixel;
if (!_loaded) return;
DrawGrid();
Graphics gfx = e.Graphics;
gfx.DrawImage(_drawArea, -AutoScrollPosition.X, -AutoScrollPosition.Y, _drawArea.Width, _drawArea.Height);
gfx.Dispose();
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
}
}
It displays everything but for some reason when I scroll the lines distort!
Here is a link of what it looks like without scrolling (what I would like it to look like)
http://img130.imageshack.us/i/should.png/
Here is a link to what it looks like when scrolled:
http://img139.imageshack.us/i/isnt.png/[^]
The control has no embedded stuff (ie the auto scroll is applied directly to the blank box that appears by default when creating a new control).
Thanks !
|
|
|
|
|
Hi again,
the problem with AutoScroll is Windows, while scrolling, will copy and move that part of the painting that it can reuse, and order your Paint handler to only paint the new stuff, the part that becomes visible by scrolling. And that interferes with your intentions.
Furthermore, your code is much too complex; you are using an image, there is no need for, nor advantage in, doing that. Here is a simple example that works well; I use a specialized panel to get double-buffering, and I invalidate the (entire) panel when scrolling, forcing an all-paint, no-copy approach.
Panel p;
int nHor=40;
int nVert=10;
int wid=20;
int hei=20;
public void Demo() {
Form f=new Form();
f.Bounds=new Rectangle(0, 0, 500, 500);
p=new UserDrawnPanel();
p.Bounds=new Rectangle(20, 20, 400, 400);
p.AutoScroll=true;
p.AutoScrollMinSize=new Size(nHor*wid+10, nVert*hei+10);
p.BackColor=Color.White;
p.Paint+=new PaintEventHandler(p_Paint);
p.Scroll+=new ScrollEventHandler(p_Scroll);
f.Controls.Add(p);
f.Show();
}
void p_Scroll(object sender, ScrollEventArgs e) {
log("Scroll="+e.NewValue);
p.Invalidate();
}
void p_Paint(object sender, PaintEventArgs e) {
Graphics g=e.Graphics;
log("ClipRectangle="+e.ClipRectangle);
log("AutoScrollPosition="+p.AutoScrollPosition);
g.TranslateTransform(p.AutoScrollPosition.X, p.AutoScrollPosition.Y);
for (int y=0; y<=nVert; y++) g.DrawLine(Pens.Black, 0, y*hei, nHor*wid, y*hei);
for (int x=0; x<=nHor ; x++) g.DrawLine(Pens.Black, x*wid, 0, x*wid, nVert*hei);
}
class UserDrawnPanel : Panel {
public UserDrawnPanel() {
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
}
BTW: you can safely ignore the log statements.
|
|
|
|
|
Thanks again it works well
|
|
|
|
|
you're welcome.
|
|
|
|
|
hi all, How to create xmpp client using C#? I want to develop an application that will chat with xmpp server like jabber etc?
it's manjeet!
|
|
|
|
|
choose a single forum to ask your question, and stick to it.
|
|
|
|
|
Personally I think using smiley's randomly is just damn annoying.
Anyway this may be of use, http://tinyurl.com/28nfze4[^]
Programming is 10% science, 20% ingenuity, and 70% getting the ingenuity to work with the science.
WYSIWYMGIYRRLAAGW: What You See Is What You Might Get If You’re Really Really Lucky And All Goes Well.
|
|
|
|
|
Hi,
I am trying to prevent users from resizing the form window. I have set:
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.ControlBox = false;
It prevents user from resizing except that if I doouble-click on the title bar on top, it resizes. Is there a way to prevent this as well?
Thanks.
|
|
|
|
|
Hi,
if you were to have
if (WindowState==FormWindowState.Normal) WindowState = FormWindowState.Maximized;
within the Form's Resize handler, you probably would get what you want (a Form that is either Maximized or Minimized).
And I as a user would probably hate your app and remove it from my system right away.
I like an app to remember its window bounds and reuse the same value next time around, and not to dictate how I choose to use my system.
|
|
|
|
|
I understand it is not user friendly but it is not supposed to be. This is for a kiosk style app and it is the only app running and should always be in maximze state. I would also remove any app from my machine if it dictates how it should be alwyas be displayed.
|
|
|
|
|
In case someone else has the same issue, this is how I solved it:
protected override void WndProc(ref System.Windows.Forms.Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
const int WM_NCDOUBLECLICK = 0x00A3;
switch(message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
// Non-client double click
case WM_NCDOUBLECLICK:
return;
}
base.WndProc(ref message);
}
|
|
|
|
|
That may be both unnecessary and insufficient; if the application shows in the task bar, you can right click there and choose "Restore".
|
|
|
|
|
Thanks Luc. It is a kiosk app and I am actually in the process of finding some way to clamp down on what users can do (disable CTL-ALT-DEL, ALT-TAB, etc., remove task bar, ...)
In case anyone knows how to accomplish these, i would really appreciate a sample or pointing me to right direction.
|
|
|
|
|
You should have said so right away. I have no experience with kiosk mode, but the topic pops up regularly around here; the best reply seems to be this one[^]. For more, use CodeProject's message search facility, or Google.
|
|
|
|
|
I would like to have the grid automatically add a new row when the user presses "Tab" from the last cell in the last row of the grid.
I have set AllowUserAddRows property to "false"
Thanks,
Sri
|
|
|
|
|