我只希望更改某些行标题的背景颜色而不会丢失DataGridView附带的炫酷默认窗口样式:
Grid.EnableHeadersVisualStyles = false;
for(int i=0; i<Grid.Rows.Count; i++)
{
if ( /*I want to change this row */)
{
DataGridViewCellStyle rowStyle = Grid.RowHeadersDefaultCellStyle;
rowStyle.BackColor = Color.Wheat;
Grid.Rows[i].HeaderCell.Style = rowStyle;
}
}
Run Code Online (Sandbox Code Playgroud)
一旦我这样做,我就会失去对列的MouseOver蓝色效果,并且列上的排序箭头显示为灰色.我试图将列标题设置为defaultColHeaderStyle无济于事.行标题更改为所需的颜色,其列标题将失去其光滑的Windows样式.有帮助吗?
不确定在这里使用的确切条款,所以任何帮助将不胜感激.
为了最简单,我有一个表单应用程序.当我加载"form.exe"时,表单有一个控件,一个菜单.此菜单有一个菜单项"退出".我想要的是,当表单加载时,能够将参数传递给此表单应用程序,该应用程序指定可以添加专用方法,控件等的DLL.
现在当我加载"form.exe add_plugable.dll"时,我的菜单有另一个菜单项"添加".当我加载"form.exe add_plugable.dll remove_pluggable.dll"时,菜单中有3个项目"退出","添加"和"删除".
希望这是有道理的.我需要在Forms应用程序中包含什么以及如何创建DLL?我知道我需要一个通用接口,但不知道如何使用命名空间和接口以及抽象类来完成此操作.
谢谢!
这适用于任何语言,但我标记了c#,因为这是我现在使用的.
当两个条件中的任何一个为真时,我有一些我想要运行的语句,但是根据哪个条件为真,可以运行一些额外的特殊语句(只有一个可以为真)
if( condition1 || condition2 )
{
statement1;
statement2;
if( condition1 )
additional_statement1;
else // (condition2)
additional_statement2;
}
Run Code Online (Sandbox Code Playgroud)
这看起来很草率(我测试了两次"condition1")并且只使用了OR语句,因为我希望两种条件都有相同的响应,但现在增强需要响应略有不同.无论如何要漂亮吗?
我有一些从接口派生的类,我希望能够检入代码以查看传入的对象是否是从该接口派生的,但我不确定该方法是否正在调用...
interface IFile
{
}
class CreateFile : IFile
{
string filename;
}
class DeleteFile : IFile
{
string filename;
}
// Input here can be a string or a file
void OperateOnFileString( object obj )
{
Type theType = obj.GetType();
// Trying to avoid this ...
// if(theType is CreateFile || theType is DeleteFile)
// I dont know exactly what to check for here
if( theType is IFile ) // its not, its 'CreateFile', or 'DeleteFile'
print("Its an IFile …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组,我想在中心的某处添加一个新值,但不知道如何执行此操作.任何人都可以为我制作这种方法吗?
void AddValueToArray(String ValueToAdd, String AddAfter, ref String[] theArray) {
// Make this Value the first value
if(String.IsNullOrEmpty(AddAfter)) {
theArray[0]=ValueToAdd; // WRONG: This replaces the first Val, want to Add a new String
return;
}
for(int i=0; i<theArray.Length; i++) {
if(theArray[i]==AddAfter) {
theArray[i++]=ValueToAdd; // WRONG: Again replaces, want to Add a new String
return;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个查询:
SELECT *
FROM myDB.Table
WHERE KEY='a' OR
WHERE KEY='b' OR
WHERE KEY='c' OR ...
Run Code Online (Sandbox Code Playgroud)
我需要在表中大约150个表行完成大约500,000.有更好/更快的方法吗?
我有一个非常大的文本文件,超过1GB,并且有一个代表行号的整数列表,需要生成另一个文件,其中包含新文件中原始文件行号的文本。
原始大文件示例:
ogfile line 1
some text here
another line
blah blah
Run Code Online (Sandbox Code Playgroud)
因此,当我得到“ 2,4,4,1”的列表时,输出文件应为:
some text here
blah blah
blah blah
ogfile line 1
Run Code Online (Sandbox Code Playgroud)
我试过了
string lineString = File.ReadLines(filename).Skip(lineNumList[i]-1).Take(1).First();
但这要花很长时间,因为必须读取文件,跳到有问题的行,然后在下一次重新读取...而且我们正在谈论1GB文件中的数百万行,而我List<int>
是成千上万的行号。
是否有更好/更快的方法来读取单行,或者让读者跳到特定的行号而不逐行“跳过”?
我有ac#form,初始化时间需要一段时间(它从服务器获取信息,并填充TreeView).现在,代码看起来类似于:
public class myForm : Form
{
InitializeComponent();
List<Location> locations = getServerLocations(); // Server call
foreach( Location loc in locations )
{
List<POI> POIs = loc.getLocationPOIs(); // Server call
foreach( POI poi in POIs )
{
List<POIDetails> = poi.getPOIDetails(); // Server call
....
}
}
}
Run Code Online (Sandbox Code Playgroud)
你得到了我认为的观点......所以有一棵大树,我知道在用户扩展树之前我不能一直打电话.但目的是我只希望表单显示,在工具条上加载"加载...",同时所有处理和服务器都会发生.
现在,好像我还没有加载应用程序,因为在完成所有调用之前,没有任何内容会显示给用户.
我有一些类,并希望根据开关更改特定类的特定实例中的布尔值,但似乎无法得到值的"指针",我只是得到一个副本.
Class aClass;
Class bClass;
Class cClass;
public class Class
{
public bool b = true;
...
}
void Method(int i)
{
bool localBool;
switch(i)
case 1:
localBool = aClass.b;
break;
case 2:
localBool = bClass.b;
break;
case 3:
localBool = cClass.b;
break;
localBool = false; // This changes the localBool, but not Class.b
}
Run Code Online (Sandbox Code Playgroud)
编辑:如果我在课堂上有3个布尔而不是3个课程怎么办?
Class aClass;
public class Class
{
public bool a = true;
public bool b = true;
public bool c = true;
...
}
void …
Run Code Online (Sandbox Code Playgroud) 我搜索了互联网并没有立即看到一个解决方案,应该很简单,但我只是想不通.
我需要在只传入基类的方法中获取派生类Type:
class Base
{
}
class Derived1 : Base
{
}
class Derived2 : Base
{
}
void SomeMethod(Base obj)
{
Type baseType = obj.GetType();
Type derivedType = obj.????
}
void Main()
{
Base d1 = new Derived1();
Base d2 = new Derived2();
SomeMethod(d1);
SomeMethod(d2);
}
Run Code Online (Sandbox Code Playgroud) c# ×9
arrays ×1
datagridview ×1
delay ×1
file ×1
filereader ×1
forms ×1
interface ×1
pluggable ×1
pointers ×1
polymorphism ×1
sql ×1
streamreader ×1
styles ×1
treeview ×1
types ×1
winforms ×1